In iOS development, Singleton is one of the most useful design patterns. It is the most useful way to share data between codes without passing parameters manually. For more information about Singleton and other design patterns, see this book: "Cocoa design pattern" background Singleton is an important concept, which is an extremely convenient design model. A large number of Singleton concepts are used in the iPhone SDK. For example, the sharedApplication method of UIApplication returns a UIApplication instance of the current application at any time. How to implement a singleton class using the following code: MyManager. h # import <foundation/Foundation. h> @ interfaceMyManager: NSObject {NSString * someProperty;} @ property (nonatomic, retain) NSString * someProperty; + (id) sharedManager; @ end MyManager. m # import "MyManager. h "@ implementationMyManager @ synthesizesomeProperty; # pragmamark Singleton Methods + (id) sharedManager {static MyManager * sharedMyManager = nil; static dispatch_once_to NceToken; dispatch_once (& onceToken, ^ {sharedMyManager = [[self alloc] init] ;}); return sharedMyManager;}-(id) init {if (self = [super init]) {someProperty = [[NSString alloc] initWithString: @ "Default Property Value"] ;}return self ;}- (void) dealloc {// shocould never be called, but justhere for clarity really .} @ end we define a static variable named sharedMyManager, Which is instantiated only once in the sharedManager method. Using the dispath_once method of GCD, we ensure that the sharedMyManager method is created only once. This is thread-safe, so you don't have to worry about it. However, if you do not want to use GCG, you can also implement the sharedManager method as follows: non-GCD code + (id) sharedManager {@ synchronized (self) {if (sharedMyManager = nil) sharedMyManager = [[self alloc] init];} returnsharedMyManager;} calls the singleton object: MyManager * sharedManager = [MyManager sharedManager]. In my code, this code is used in many places. I use these Singleton objects to process CoreLocation or CoreData. Non-ARC Code if you do not use ARC (not recommended), you should use the following code: MyManager. h (non-ARC) # import "MyManager. h "static MyManager * sharedMyManager = nil; @ implementation MyManager @ synthesize someProperty; # pragma mark Singleton Methods + (id) sharedManager {@ synchronized (self) {if (sharedMyManager = nil) sharedMyManager = [[super allocWithZone: NULL] init];} return sharedMyManager;} + (id) allocWithZone :( NSZone *) zone {return [self sharedManager] retain];} -(id) copyWithZone :( NSZone *) zone {return self;}-(id) retain {return self;}-(unsigned) retainCount {return UINT_MAX; // denotes anobject that cannot be released}-(oneway void) release {// never release}-(id) autorelease {return self;}-(id) init {if (self = [super init]) {someProperty = [[NSString alloc] initWithString: @ "Default PropertyValue"];} return self;}-(void) dealloc {// shocould never be called, but just here for clarity really. [someProperty release]; [super dealloc] ;}@ end