Prepare for Segue in Swift Prepare for Segue in Swift ios ios

Prepare for Segue in Swift


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.


Swift 4, Swift 3

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {    if segue.identifier == "MySegueId" {        if let nextViewController = segue.destination as? NextViewController {                nextViewController.valueOfxyz = "XYZ" //Or pass any values                nextViewController.valueOf123 = 123        }    }}


I think the problem is you have to use the ! to unbundle identifier

I have

override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {        if segue!.identifier == "Details" {            let viewController:ViewController = segue!.destinationViewController as ViewController            let indexPath = self.tableView.indexPathForSelectedRow()            viewController.pinCode = self.exams[indexPath.row]        }    }

My understanding is that without the ! you just get a true or false value