单例模式

版权所有,禁止匿名转载;禁止商业使用。
import "ZCPerson.h"
@interface ZCPerson()
@end
@implementation ZCPerson
static XMGPerson *_person;
(instancetype)allocWithZone:(struct _NSZone *)zone 
{
 static dispatch_once_t onceToken;
 dispatch_once(&onceToken, ^{ 
_person = [super allocWithZone:zone]; 
});
return _person; 
}
(instancetype)sharedPerson 
{
 static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{
 _person = [[self alloc] init];
 }); 
    return _person;
}
 
   (id)copyWithZone:(NSZone *)zone 
{
 return _person; 
} 
@end
0 0