国产探花免费观看_亚洲丰满少妇自慰呻吟_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;

}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 延庆县| 定边县| 沁源县| 青阳县| 松潘县| 莱芜市| 彭水| 兴安县| 扎赉特旗| 敖汉旗| 开封市| 会泽县| 高台县| 息烽县| 平利县| 谷城县| 荆门市| 青神县| 治县。| 内丘县| 永平县| 赤壁市| 黄平县| 阳江市| 涞水县| 奉化市| 聂荣县| 大足县| 门源| 灯塔市| 黑龙江省| 莆田市| 兴宁市| 黄冈市| 襄垣县| 博爱县| 延川县| 佛教| 嵊州市| 旌德县| 嵊州市|