码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 单例模式范例

时间:2016-04-10 21:17:42      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

 

The singleton pattern is useful for creating objects that are shared across the entire application,

such as an HTTP client or a notification manager,

or objects that may be expensive to create, such as formatters.

 

+ (instancetype)sharedInstance {
  static id _sharedInstance = nil;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
      _sharedInstance = [[self alloc] init];
  });

  return _sharedInstance;
}

 

iOS 单例模式范例

标签:

原文地址:http://www.cnblogs.com/ficow/p/5375337.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!