iOS 单例模式范例

 

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;
}

 

posted @ 2016-04-10 20:30  Ficow  阅读(159)  评论(0编辑  收藏  举报