IOS单例模式代码示例

@interface MySingleton : NSObject

  • (instancetype)sharedInstance;

@end

@implementation MySingleton

  • (instancetype)sharedInstance { static MySingleton *sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[self alloc] init]; }); return sharedInstance; }

@end

zip 文件大小:144.07KB