Instance Method

instantiateViewController(withIdentifier:)

Instantiates and returns the view controller with the specified identifier.

Declaration

func instantiateViewController(withIdentifier identifier: String) -> UIViewController

Parameters

identifier

An identifier string that uniquely identifies the view controller in the storyboard file. You set the identifier for a given view controller in Interface Builder when configuring the storyboard file. This identifier is not a property of the view controller object itself and is used only by the storyboard file to locate the view controller.

If the specified identifier does not exist (or is nil) in the storyboard file, this method raises an exception.

Return Value

The view controller corresponding to the specified identifier string. If no view controller is associated with the string, this method throws an exception.

Discussion

You use this method to create view controller objects that you want to manipulate and present programmatically in your application. Before you can use this method to retrieve a view controller, you must explicitly tag it with an appropriate identifier string in Interface Builder.

This method creates a new instance of the specified view controller each time you call it.

See Also

Instantiating Storyboard View Controllers

func instantiateInitialViewController() -> UIViewController?

Instantiates and returns the initial view controller in the view controller graph.