Lazy initialization in Objective-C
Lazy initialization in Objective-C can be simple done via BloodMagic
@interface ViewController : UIViewController
<BMLazy>
@property (nonatomic, strong) ProgressViewService *progressViewService;
@property (nonatomic, strong) ResourceLoader *resourceLoader;
@end
@implementation ViewController
@dynamic progressViewService;
@dynamic resourceLoader;
- (void)loadResources
{
[self.progressViewService showProgressInView:self.view];
self.resourceLoader.delegate = self;
[self.resourceLoader loadResources];
}
@end
And that’s it. Both @dynamic
properties are created by a first call to self.progressViewService
and self.resourceLoader
.
Written by AlexDenisov
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Magic
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#