Instance Method


Called when a segue is about to be performed.


optional func prepare(for segue: NSStoryboardSegue, sender: Any?)



The segue object containing information about the view controllers involved in the segue.


The object that initiated the segue. You might use this parameter to perform different actions based on which control (or other object) initiated the segue.


The default implementation of this method does nothing; you can override it to pass relevant data to the new view controller or window controller, based on the context of the segue. The segue object describes the transition and includes references to both controllers involved in the segue.

Segues can be triggered from multiple sources, so use the information in the segue and sender parameters to disambiguate between different logical paths in your app. For example, if the segue originated from a table view, the sender parameter would identify the cell that the user clicked. You could use that information to set the data on the destination view controller.

See Also

Working with Storyboard Segues