學科:IOS/KB/Singletons
< Subject:IOS | KB
一個線程安全的單例參考:
+ (MyClass *)sharedInstance { static MyClass *sharedInstance = nil; if(sharedInstance == nil) { @synchronized(self) { if (sharedInstance == nil) sharedInstance = [[self alloc] init]; } } return sharedInstance; }