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;
}
原文地址:https://www.cnblogs.com/ficow/p/5375337.html