Instance Method


Notifies the view controller that a segue is about to be performed.


func prepare(for segue: UIStoryboardSegue, 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. Subclasses override this method and use it to configure the new view controller prior to it being displayed. The segue object contains information about the transition, including references to both view controllers that are involved.

Because segues can be triggered from multiple sources, you can 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 table view cell that the user tapped. You could then use that information to set the data on the destination view controller.

See Also

Interacting with Storyboards and Segues

var storyboard: UIStoryboard?

The storyboard from which the view controller originated.

func shouldPerformSegue(withIdentifier: String, sender: Any?)

Determines whether the segue with the specified identifier should be performed.

func performSegue(withIdentifier: String, sender: Any?)

Initiates the segue with the specified identifier from the current view controller'€™s storyboard file.

func allowedChildViewControllersForUnwinding(from: UIStoryboardUnwindSegueSource)

Returns an array of child view controllers that should be searched for an unwind segue destination.

func childViewControllerContaining(UIStoryboardUnwindSegueSource)

Returns the child view controller that contains the source of the unwind segue.

func canPerformUnwindSegueAction(Selector, from: UIViewController, withSender: Any)

Called on a view controller to determine whether it wants to respond to an unwind action.

func unwind(for: UIStoryboardSegue, towardsViewController: UIViewController)

Called when an unwind segue transitions to a new view controller.