8
votes

I just realised that, in the current Xcode 8 beta 6, when I hook up an unwind action to, e.g., a bar button item in a modally presented view controller to unwind the modal presentation segue and present the view controller previously in the navigation stack, Xcode adds an "WithSegue" to the name of the existing @IBActions that can be used for this purpose - and that this breaks the unwind segue (it won't be performed). If I edit the storyboard file in source code (as XML), and remove this "WithSegue" from the @IBAction method identifier, the segue works as expected. For example, my unwind method in the originating view controller (the destination for the unwind segue) is called "unwindFromSettingsToTableView" - and Xcode/Interface Builder rename this method to "unwindFromSettingsToTableViewWithSegue" when I CTRL-connect the bar button item in the modally presented view controller to the view controller's exit item in the scene dock.

Is this a bug in Xcode 8 beta? Is it a known bug? Am I missing something?

I checked my previously connected unwind segues (connected in Xcode 7), and they don't have this "WithSegue" suffix. If I delete those existing "vintage" unwind segues, and connect them again in Xcode 8, Interface Builder now suggests the same method name with the "WithSegue" suffix - and those segues break. When I delete the suffix in storyboard source code, the unwind segue works again.

Would be great to get any indications. This behaviour is annoying.

Best wishes! Björn

3
Perhaps you can update question with example of how unwindFromSettingsToTableView was declared (e.g. did you use _ with parameter name?). Also, you might want to try reproducing this behavior you describe in a new test project, because I cannot reproduce the behavior you describe in beta 6. Let's make sure there just isn't some problem with your current project.Rob
"Is this a bug in Xcode 8 beta" No it is not.matt

3 Answers

8
votes

In Swift 3, if you don't want it to add WithSegue, define your @IBAction method to not name the first parameter:

@IBAction func unwindHome(_ segue: UIStoryboardSegue) {
    // this is intentionally blank
}

If you don't use that _ syntax, when it goes to hook up the @IBAction, it will add the WithSegue to the name.

When I use the above syntax for my unwind action, it works fine in Xcode 8, beta 6.

As an aside, when I don't use the _ syntax shown above in beta 6, it names the action unwindHomeWithSegue but it still works with that longer name, with no editing of the storyboard XML needed. I wonder if your non-functioning unwind segue is a result of some other issue. We need a reproducible example of the problem to diagnose further. Perhaps you can share a MCVE.

3
votes

I had the same issue as OP, using swift 2.3 in xcode 8 beta 6.

This post using ios 8 explained how to unwind the segue programmatically. And in step three to select the unwind segue in the Document Outline.

Selecting this and changing unwindToSecondVCWithSegue in Action on the upper right side to unwindToSecondVC so it matches the code solved my issue.

@IBAction func unwindToSecondVC (segue: UIStoryboardSegue) {
    print("unwindToSecondVC")
}

unwindSegue

0
votes

This problem still occur with the released version of Xcode 8.0 not just the betas.

What I noticed in an unwind segue though is that the suffix was "WithUnwindSegue" instead of "WithSegue"

I too was using an swift 2.3 project and created an unwind segue. Similar to the above, while on the storyboard, the fix is to remove WithUnwindSegue suffix in the Action property (field) of the segue's Attributes Inspector.