单利

继承芋NSObjest

。。。h。。+ (instancetype)sharePerson;

staticPerson*_person =nil;

+ (instancetype)sharePerson

{

staticdispatch_once_tonceToken;

dispatch_once(&onceToken, ^{

_person= [[Personalloc]init];

});

return_person;

}


写法二

+ (instancetype)alloc

{

staticdispatch_once_tonceToken;

dispatch_once(&onceToken, ^{

//里面的代码只执行一遍

_person= [superalloc];

});

return_person;

}

你可能感兴趣的:(单利)