Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters when performing a segue using performSegueWithIdentifier in Swift [duplicate]

I am calling a segue programatically, Can any one please help me how can pass parameters ?

@IBAction func update(sender: AnyObject) {

    self.performSegueWithIdentifier("showUpdate", sender: nil)
}
like image 482
venkat kotu Avatar asked Feb 14 '16 21:02

venkat kotu


People also ask

What is Sender in Perform segue?

The string that identifies the triggered segue. In Interface Builder, you specify the segue's identifier string in the attributes inspector. This method throws an Exception handling if there is no segue with the specified identifier. sender. The object that you want to use to initiate the segue.


1 Answers

Swift 4:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "ExampleSegueIdentifier" {
        if let destinationVC = segue.destination as? ExampleSegueVC {
            destinationVC.exampleStringProperty = "Example"
        }
    }
}

Swift 3:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "ExampleSegueIdentifier" {
            if let destinationVC = segue.destinationViewController as? ExampleSegueVC {
                destinationVC.exampleStringProperty = "Example"
            }
        }
    }
like image 127
Ryan Huebert Avatar answered Oct 11 '22 05:10

Ryan Huebert