国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ARC和MRC實現單例模式

2019-11-14 18:33:13
字體:
來源:轉載
供稿:網友

代碼如下,可直接拷貝到頭文件中

#define singleton_h(name) +(instancetype)shared##name# if __has_feature(objc_arc) //ARC#define singleton_m(name) /static id _instance;/+(id)allocWithZone:(struct _NSZone *)zone/{/    static dispatch_once_t onceToken;/    dispatch_once(&onceToken, ^{/        _instance = [super allocWithZone:zone];/    });/    return _instance;/}//+(instancetype)shared##name/{/    static dispatch_once_t onceToken;/    dispatch_once(&onceToken, ^{/        _instance = [[self alloc] init];/    });/    return _instance;/}//+(id)copyWithZone:(struct _NSZone *)zone/{/    return _instance;/}#else //非ARC#define singleton_m(name) /static id _instance;/+(id)allocWithZone:(struct _NSZone *)zone/{/static dispatch_once_t onceToken;/dispatch_once(&onceToken, ^{/_instance = [super allocWithZone:zone];/});/return _instance;/}//+(instancetype)shared##name/{/static dispatch_once_t onceToken;/dispatch_once(&onceToken, ^{/_instance = [[self alloc] init];/});/return _instance;/}//+(id)copyWithZone:(struct _NSZone *)zone/{/return _instance;/}/-(oneway void)release/{/    /}/-(instancetype)autorelease/{/    return _instance;/}/-(instancetype)retain/{/    return _instance;/}/-(NSUInteger)retainCount/{/    return 1;/}#endif

MRC要重寫四個方法:

-(oneway void)release

{   

}

-(instancetype)autorelease

{

    return self;

}

-(instancetype)retain{

    

    return self;

}

-(NSUInteger)retainCount{

    return 1;

}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南溪县| 涡阳县| 巴塘县| 宜兰市| 镇康县| 华蓥市| 常州市| 武宁县| 丹凤县| 北票市| 泌阳县| 华容县| 马关县| 枞阳县| 定襄县| 曲松县| 津市市| 武乡县| 阳东县| 永吉县| 城固县| 永嘉县| 古丈县| 集安市| 涿鹿县| 武城县| 子洲县| 青海省| 凤山市| 琼中| 晋州市| 观塘区| 英超| 丰镇市| 红桥区| 嘉善县| 阿拉善左旗| 龙游县| 德化县| 宜丰县| 颍上县|