#import "Abc.h" @implementation Abc + (Abc *)sharedInstance { static Abc *abc = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ abc = [[Abc alloc] init]; }); return abc; } @end
这是Objective-c的singleton写法。
#import "Abc.h" @implementation Abc + (Abc *)sharedInstance { static Abc *abc = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ abc = [[Abc alloc] init]; }); return abc; } @end
这是Objective-c的singleton写法。
转载于:https://www.cnblogs.com/mystory/archive/2013/02/18/2915859.html
来源:https://blog.csdn.net/weixin_30287169/article/details/99019307