Last active
March 15, 2016 22:18
-
-
Save vinnybad/746ed1cce9874ef534a3 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Lazily initializes an object. Mainly used for reducing boilerplate code. | |
*/ | |
#define DEFINE_LAZY_GETTER(type, name, initialValueBlock) \ | |
- (type)name { \ | |
if (! _ ## name) { \ | |
_ ## name = initialValueBlock(); \ | |
} \ | |
return _ ## name; \ | |
} |
This file contains 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
// example usage | |
DEFINE_LAZY_GETTER( Person *, homeOwner, ^{ | |
return [Person new]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment