It seems that view is a lazy property (but not using the lazy modifier) ââ- in fact, if you read the inline comment (cmd + click on the view property to open the source), it says:
A getter first calls [self loadView] if the view is not already set. Subclasses should be called super if they redefine the setter or receiver.
and near loadView() :
Here subclasses should create their own hierarchy of views if they don't use a thread. Never be called directly.
I suppose that:
- the standard implementation creates an empty view if it is not created otherwise
- supported by an optional variable (not public)
- in case of low memory conditions, the substitution variable is set to zero, freeing an instance of the form
- If you try to access a property when the support variable is nil, it will create a new instance
therefore, its implementation should be conceptually similar:
private var _view: UIView? var view: UIView { if _view == nil { loadView() } return _view! } func loadView() { if _view == nil {
source share