单例就是只有一个实例。
两种常见的创建方法:
1. :
static A *a = nil;
+ (A *)shareInstance {
if (!a)
a = [[self alloc] init];
return a;
}
2:
+ (A *)shareInstance {
static A *a = nil;
static dispatch_once_t once;
dispatch_once(&once, ^{
a = [[self alloc] init];
});
return a;
}
原文:http://www.cnblogs.com/small-octopus/p/4818789.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!