Xcode 6 Storyboard Unwind Segue with Swift Not Connecting to Exit Xcode 6 Storyboard Unwind Segue with Swift Not Connecting to Exit xcode xcode

Xcode 6 Storyboard Unwind Segue with Swift Not Connecting to Exit


This is a known issue with Xcode 6:

Unwind segue actions declared in Swift classes are not recognized by Interface Builder

In order to get around it you need to:

  1. Change class MyViewController to @objc(MyViewController) class MyViewController
  2. Create an Objective-C header file with a category for MyViewController that redeclares the segue action.

    @interface MyViewController (Workaround)- (IBAction)unwindToMyViewController: (UIStoryboardSegue *)segue;@end
  3. In the storyboard, select the instance of MyViewController, clear its custom class, then set it back to MyViewController.

After these steps you are able to connect buttons to the exit item again.

Xcode 6 Release Notes PDF, Page 10


Instead of using the Objective-C workaround, Xcode 6 Beta 4, which can now be installed, supports the connection of unwind segues in the Interface Builder. You can update now from the iOS Dev center. Control-click and drag from the UI item you want to trigger the segue to the exit icon, and select the function unwindToSegue after having put the following code in the destination view controller.

@IBAction func unwindToSegue (segue : UIStoryboardSegue) {}


I was able to finally get it to work; the xcode6 IB is really fragile right now (crashes a lot too). I had to restart the IDE before I could connect the nav bar button item to the exit item. I ended up re-creating my test project and following the above suggestion (Xcode 6 Release Notes PDF, Page 10) to get it to work. In addition, when adding the .h file, I made sure to select my project target, which was unchecked by default. I also created my controller swift stub via the Cocoa Touch Class template (vs empty swift file). I used a modal segue in my nav controller.

ListTableViewController.h

#import <UIKit/UIKit.h>@interface ListTableViewController- (IBAction)unwindToList: (UIStoryboardSegue *)segue;@end

ListTableViewController.swift

import UIKit@objc(ListTableViewController) class ListTableViewController: UITableViewController {    @IBAction func unwindToList(s:UIStoryboardSegue) {        println("hello world");    }}

hope that helps