Through the development of the Apple SDK and all the iterations of different Macros to auto-generate singletons, there is now a simple, straight-forward way of adding singletons to any Objective-C class:
1 2 3 4 5 6 7 8 9 |
+ (id)sharedInstance { static dispatch_once_t pred = 0; __strong static id _sharedObject = nil; dispatch_once(&pred, ^{ _sharedObject = [[self alloc] init]; // or some other init method }); return _sharedObject; } |