At this start of this month I mentioned an interesting project providing an NSString category that makes it easy to get UIColor selectors by name or value from Nicolas Goutaland.
Here’s another interesting project submitted by Nicolas that makes it easy to perform lazy instantiation (initialized only when used) of Objective-C properties saving on boilerplate code called LazyProperty.
Lazyproperty includes a simple macro that will automatically make properties use the lazy instantiation pattern (properties must be set to nonatomic, strong).
This source code snippet from the readme shows the macro in action:
…
// Lazy properties
@property (nonatomic, strong) SimpleViewController *simpleViewController; // Will be used modally
@property (nonatomic, strong) DetailViewController *detailViewController; // Will be pushed from tableview
@end
@implementation DemoViewController
…
// Magic happens here. Write macros at the end of the file, to keep it clean. Use property name
LAZY_PROPERTY(simpleViewController);
LAZY_PROPERTY(detailViewController);
@end
You can find LazyProperty on Github here.
A nice macro for easy lazy instantiation saving on code typing and making for easier memory management.
- Code Snippet: Log Meaningful Information About (Nearly) Any Type In Objective-C
- Tutorial: Beginners Objective-C Understand The Self Keyword And Properties
- Open Source Library Providing Basic Generics Within Objective-C
- Objective-C Dependency Injection Framework Using A Spring-Style Approach
- Open Source Tween Library W/Concise UIView Animation Syntax And Ability To Tween Any Numeric Value
Original article: A Macro For Easy Clean Lazy Instantiation Of Properties In Objective-C
©2014 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.




