iOS单例
程序员文章站
2022-07-13 23:38:58
...
+(SingleObject *)sharedInstance{
static SingleObject * ourSharedInstance = nil;
if (ourSharedInstance)
{
static dispatch_once once ;
dispatch_once(&once,^{
// ourSharedInstance = [[SingleObject alloc] init];
// 使用[self class]兼容子类
ourSharedInstance = [[[self class] alloc] init];
});
}
return ourSharedInstance;
}