Segue Methods and Their Objectives

Home / Uncategorized / Segue Methods and Their Objectives

When I press the button, I want to initiate new view controller and I want to pass some information into new view controller. This is handled by without any segue methods by using global variables.

However, If I use segue method, Which one of them do I have to use ?

performSegue() or shouldPerformSegue()

You have to call
func performSegue(withIdentifier identifier: String,
sender: Any?)
The above method will initiate your segue and you can push your next view controller.

For your info
func shouldPerformSegue(withIdentifier identifier: String,
sender: Any?) -> Bool
The method will return Boolean value, that will specify if to perform segue or not. You have controller over it and you can allow segue to perform or not by return true/false from method.

true – Segue is allowed and will be performed

false – Segue is not allowed and will be aborted.

You can use this method if you want to override any segue you have defined in storyboard and want to perform any other at run time.
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *