static char kInstanceKey;
+ (instancetype)sharedManager {
id instance = objc_getAssociatedObject(self, &kInstanceKey);
if (!instance) {
instance = [[super allocWithZone:NULL] init];
objc_setAssociatedObject(self, &kInstanceKey, instance, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return instance;
}
+ (id) allocWithZone:(struct _NSZone *)zone {
return [self sharedManager] ;
}
- (id) copyWithZone:(struct _NSZone *)zone {
return [[self class] sharedManager] ;
}
参考文章:http://blog.csdn.net/wangyanchang21/article/details/50996830
网友评论