Skip to content

Instantly share code, notes, and snippets.

@axiixc
Last active December 16, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axiixc/5415946 to your computer and use it in GitHub Desktop.
Save axiixc/5415946 to your computer and use it in GitHub Desktop.
@interface MyClass : NSObject
@property (nonatomic, strong) NSComplexThing * myThing;
@end
#import "MyClass.h"
#define LAZY_GETTER(TYPE, NAME) \
- (TYPE)NAME { return (_##NAME = (_##NAME) ?: [self _lazyLoad_##NAME]); } \
- (TYPE)_lazyLoad_##NAME
@implementation MyClass
LAZY_GETTER(NSComplexThing *, myThing)
{
NSComplexThing * thing = [[NSComplexThing alloc] init];
thing.stuff = // .. do your super complex initializer here
return thing;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment