@interface Foo : NSObject
@property (nonatomic, strong) NSString *foo;
@end
@implementation Foo
LAZY(foo, ^{
return @"foo";
});
@end
Created
January 9, 2014 21:24
-
-
Save luisobo/8342304 to your computer and use it in GitHub Desktop.
Lazy property
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define VARNAME(_name) _ ## _name | |
#define LAZY(_name, _init...) -(id)_name {\ | |
if (!VARNAME(_name)) {\ | |
VARNAME(_name) = _init();\ | |
}\ | |
return VARNAME(_name);\ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment