首页 > 移动平台 > 详细

iOS 单例模式范例

时间:2016-04-10 21:14:56      阅读:142      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!