iOS设计模式-单例

首选:
+ (instancetype)managerCenter {
static UserInfoManagerCenter *center = nil;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
center = [[UserInfoManagerCenter alloc] init];
});
return center;
}

或者:
+ (instancetype)managerCenter {
static UserInfoManagerCenter *center = nil
if (center == nil) {
center = [[UserInfoManagerCenter alloc] init];
}
return center;
}
或者:
+ (void)initialize {
static UserInfoManagerCenter *center = nil;
if (self == [UserInfoManagerCenter class]) {
center = [[UserInfoManagerCenter alloc] init];
}
}

你可能感兴趣的:(iOS设计模式-单例)