1. Lazy Loading Basic
Lazy Loading--also known as deferred loading--is loaded when needed (low efficiency, small memory footprint). The so-called lazy load, write is its get method.
Note: If it is lazy loading, it is important to be aware of whether there is already, if not then to instantiate
2. Benefits of using lazy loading:
(1) You do not have to write all the code of the created object in the Viewdidload method, the code is more readable
(2) Each control's getter method is responsible for the respective instantiation processing, the code is independent of each other, loosely coupled
-(UIButton *) button {
if (!_button) {
_button = [UIButton Buttonwithtype:uibuttontypesystem];
_button.center =self.view.center;
_button.bounds = CGRectMake (0, 0, 60, 40);
_button.backgroundcolor = [Uicolor Redcolor];
[Self.view Addsubview:_button];
}
return _button;
}
Lazy Loading in iOS