Prepare for Segue in Swift

nikolaus picture nikolaus · Jun 4, 2014 · Viewed 139.4k times · Source

I'm facing the error message:

"UIStoryboardSegue does not have a member named 'identifier'"

Here's the code causing the error

if (segue.identifier == "Load View") {
    // pass data to next view
}

On Obj-C it's fine using like this:

if ([segue.identifier isEqualToString:@"Load View"]) {
   // pass data to next view
}

What am I doing wrong?

Answer

Cezar picture Cezar · Jun 4, 2014

This seems to be due to a problem in the UITableViewController subclass template. It comes with a version of the prepareForSegue method that would require you to unwrap the segue.

Replace your current prepareForSegue function with:

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "Load View") {
        // pass data to next view
    }
}

This version implicitly unwraps the parameters, so you should be fine.