Lazy loading, English name Lazyload. Also known as lazy loading, which is loaded when needed (low efficiency, small footprint). The so-called lazy load, write is its get method.
- You do not have to write the code of the object that you created all in the Viewdidload method, and the code is more readable.
- Each control's Getter method is responsible for the respective instantiation, and the code is highly independent and loosely coupled.
- Be sure to first determine if there is any.
below is the sample code @interface Viewcontroller () <CLLocationManagerDelegate>
@property (Nonatomic,strong) Cllocationmanager *locmgr;
@end
-(void) Viewdidload {
[Super Viewdidload];
Start positioning
[Self.locmgr startupdatinglocation];
}
-(Cllocationmanager *) locmgr{
if (!_locmgr) {//Determines whether it is empty
Self.locmgr = [[Cllocationmanager alloc] init];
Set up Proxy
Self.locMgr.delegate = self;
[Self.locmgr requestalwaysauthorization];
}
return _locmgr;
}
iOS Lazy load