I recently switched to a new way of implementing singletons in Objective-C. Since most of my code now is iOS 4.0+ I started using GCD and blocks as recommended by Luke Redpath (ARC compatible):
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
+ (id) sharedInstance { | |
static dispatch_once_t predicate = 0; | |
__strong static id shared = nil; | |
dispatch_once(&predicate, ^{ | |
shared = [[self alloc] init]; | |
}); | |
return shared; | |
} |