博客> 单例模式
单例模式
2017-10-19 05:29 评论:1 阅读:224 vistatinchao

import "XMGPerson.h"

@interface XMGPerson()

@end

@implementation XMGPerson

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
sina weixin mail 回到顶部