Skip to content

Instantly share code, notes, and snippets.

@luisobo luisobo/README.md
Created Jan 9, 2014

Embed
What would you like to do?
Lazy property

Usage

@interface Foo : NSObject

@property (nonatomic, strong) NSString *foo;

@end

@implementation Foo

LAZY(foo, ^{
    return @"foo";
});

@end
#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
You can’t perform that action at this time.