Skip to content

Instantly share code, notes, and snippets.

@luisobo luisobo/

Created Jan 9, 2014
What would you like to do?
Lazy property


@interface Foo : NSObject

@property (nonatomic, strong) NSString *foo;


@implementation Foo

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

#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.