DrWhat DrWhat - 5 months ago 16x
Swift Question

Swift unwind segue - Only instance methods can be declared @IBAction; and button does not connect to Exit

I've much the same problem as in this question but these solutions don't work. Currently running xcode 7.3.1.

I've a split view controller app, that modally presents a save record view controller. On the save VC, there are a save and cancel button that should (in both cases) unwind back to the master view.

Within the Master View Controller, I have the following code:

@IBAction func unwindToSegue (segue: UIStoryboardSegue) { }

BUT, there's a compiler error: Only instance methods can be declared @IBAction. There is the suggestion to delete @IBAction, but while this removes the error I can't connect to this action in the child VC.

With or without @IBAction in the unwind method, I get the same issue described in the referenced problem - dragging a line from my UIButton to the Exit button in Storyboard IB, does not show any action to connect with.


You need to put the function inside the UIViewController.

class MasterViewController: UIViewController {
    @IBAction func unwindToSegue(segue: UIStoryboardSegue) { }