Object c 单例实现
要用到objc的单例模式,自己写了一个,发现出现内存泄漏,网上找了国外博文的方法,简单实用,于是记录下来
头文件
@interface ModelLocator : NSObject { } +(id)sharedModelLocator;
mm文件
@implementation ModelLocator static ModelLocator * _sharedModel = nil; + (void)initialize { if (self == [ModelLocator class]) { _sharedModel = [ [self alloc] init]; } } + (id)sharedModelLocator { return _sharedModel; }