Class

UIStoryboardSegue

A UIStoryboardSegue object is responsible for performing the visual transition between two view controllers. In addition, segue objects are used to prepare for the transition from one view controller to another. Segue objects contain information about the view controllers involved in a transition. When a segue is triggered, but before the visual transition occurs, the storyboard runtime calls the current view controller’s prepareForSegue:sender: method so that it can pass any needed data to the view controller that is about to be displayed.

Overview

The UIStoryboardSegue class supports the standard visual transitions available in UIKit. You can also subclass to define custom transitions between the view controllers in your storyboard file.

You do not create segue objects directly. Instead, the storyboard runtime creates them when it must perform a segue between two view controllers. You can still initiate a segue programmatically using the performSegueWithIdentifier:sender: method of UIViewController if you want. You might do so to initiate a segue from a source that was added programmatically and therefore not available in Interface Builder.

Subclassing Notes

You can subclass UIStoryboardSegue in situations where you want to provide a custom transition between view controllers in your application. To use your custom segue, create a segue line between the appropriate view controllers in Interface Builder and set its type to Custom in the inspector; you must also specify the class name of the segue to use in the inspector.

When the storyboard runtime detects a custom segue, it creates a new instance of your class, configures it with the view controller objects, asks the view controller source to prepare for the segue, and then performs the segue.

Methods to Override

For custom segues, the main method you need to override is the perform() method. The storyboard runtime calls this method when it is time to perform the visual transition from the view controller in source to the view controller in destination. If you need to initialize any variables in your custom segue subclass, you can also override the init(identifier:source:destination:) method and initialize them in your custom implementation.

Alternatives to Subclassing

If your segue does not need to store additional information or provide anything other than aperform() method, consider using the init(identifier:source:destination:performHandler:) method instead.

Symbols

Initializing a Storyboard Segue

init(identifier: String?, source: UIViewController, destination: UIViewController)

Initializes and returns a storyboard segue object for use in performing a segue.

Accessing the Segue Attributes

var source: UIViewController

The source view controller for the segue.

var destination: UIViewController

The destination view controller for the segue.

var identifier: String?

The identifier for the segue object.

Performing the Segue

func perform()

Performs the visual transition for the segue.

Creating a Custom Segue

Relationships

Inherits From

Conforms To