iOS单例的写法

参考https://www.jianshu.com/p/6b012ebc10fe

.h文件

```objective-c

#import 

@interfaceCYWinLoseSound :NSObject

+ (instancetype) shareTsetSington;

@end

```objective-c

```objective-c

.m文件

#import "FTTsetSington.h"

@implementation FTTsetSington

static FTTsetSington*_instance =nil;

+ (instancetype) shareTsetSington{

// staticdispatch_once_tonceToken;不用手打,你直接打dispatch_once会直接生成staticdispatch_once_tonceToken这句

    staticdispatch_once_tonceToken;

//dispatch_once这个函数可以使其参数内的block块只在全局执行一次从而达到目的

    dispatch_once(&onceToken, ^{

        _instance = [[self alloc] init];

    });

    return _instance;

}

@end


```objective-c

你可能感兴趣的:(iOS单例的写法)