Contents

prepare(for:sender:)

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

Declaration

func prepare(for segue: UIStoryboardSegue, sender: Any?)

Parameters

  • segue:

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

  • sender:

    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.

Mentioned in

Discussion

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

Performing segues