view
The view that the controller manages.
Declaration
var view: UIView! { get set }Mentioned in
Discussion
This property represents the root view of the view controller’s view hierarchy. The default value of this property is nil.
If you access this property when its value is nil, the view controller automatically calls the loadView() method and returns the resulting view.
Each view controller is the sole owner of its view object. Don’t associate the same view object with multiple view controllers. The only exception is that a container view controller implementation may add another view controller’s view object to its own view hierarchy. Before adding the subview, the container must first call its addChild(_:) 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 isViewLoaded to determine if the view is currently in memory. Unlike this property, isViewLoaded doesn’t force the loading of the view if it’s not currently in memory.
For more information about how a view controller loads and unloads its view, see Managing your app’s life cycle.