Instance Property

view

The view that the controller manages.

Declaration

var view: UIView! { get set }

Discussion

The view stored in this property represents the root view for the view controller'€™s view hierarchy. The default value of this property is nil.

If you access this property and its value is currently nil, the view controller automatically calls the loadView() method and returns the resulting view.

Each view controller object is the sole owner of its view. You must not associate the same view object with multiple view controller objects. The only exception to this rule is that a container view controller implementation may add this view as a subview in its own view hierarchy. Before adding the subview, the container must first call its addChildViewController(_:) method to create a parent-child relationship between the two view controller objects.

Because accessing this property can cause the view to be loaded automatically, you can use the isViewLoaded() method to determine if the view is currently in memory. Unlike this property, the isViewLoaded() property does not force the loading of the view if it is not currently in memory.

The UIViewController class can automatically set this property to nil during low-memory conditions and also when the view controller itself is finally released.

For more information about how a view controller loads and unloads its view, see View Controller Programming Guide for iOS.

See Also

Managing the View

var isViewLoaded: Bool

A Boolean value indicating whether the view is currently loaded into memory.

func loadView()

Creates the view that the controller manages.

func viewDidLoad()

Called after the controller'€™s view is loaded into memory.

func loadViewIfNeeded()

Loads the view controller’s view if it has not yet been loaded.

var viewIfLoaded: UIView?

The view controller’s view, or nil if the view is not yet loaded.

var title: String?

A localized string that represents the view this controller manages.

var preferredContentSize: CGSize

The preferred size for the view controller’s view.