标签:singleton objective-c oc obj-c
// YOURCLASSNAME.h @interface YOURCLASSNAME : NSObject +(instancetype) sharedInstance; @end
// YOURCLASSNAME.m @implementation YOURCLASSNAME + (instancetype)sharedXXX { static YOURCLASSNAME *_sharedInstance = nil; static dispatch_once_t oncePredicate; dispatch_once(&oncePredicate, ^{ // alloc & init work // [[YOURCLASSNAME alloc] init]; }); return _sharedInstance; } @end
+ (instancetype)sharedManager { static AFNetworkActivityIndicatorManager *_sharedManager = nil; static dispatch_once_t oncePredicate; dispatch_once(&oncePredicate, ^{ _sharedManager = [[self alloc] init]; }); return _sharedManager; }
标签:singleton objective-c oc obj-c
原文地址:http://blog.csdn.net/tounaobun/article/details/39432513