OC单例:
+(instancetype)sharedInstance{
static demo *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
//初始化
});
return sharedInstance;
}
//使用
[demo sharedInstance]
Swift 3.0
static var shareInstance:Demo{
struct MyStatic{
static var instance :Demo = Demo()
}
//初始化
return MyStatic.instance;
}
//使用
Demo.shareInstance