第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何實(shí)現(xiàn)與ARC兼容的Objective-C單例?

如何實(shí)現(xiàn)與ARC兼容的Objective-C單例?

慕田峪7331174 2019-08-06 13:14:28
如何實(shí)現(xiàn)與ARC兼容的Objective-C單例?在Xcode 4.2中使用自動引用計數(shù)(ARC)時,如何轉(zhuǎn)換(或創(chuàng)建)編譯和行為正確的單例類?
查看完整描述

3 回答

?
森欄

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個贊

完全一樣,你(應(yīng)該)已經(jīng)這樣做了:

+ (instancetype)sharedInstance{
    static MyClass *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[MyClass alloc] init];
        // Do any other initialisation stuff here
    });
    return sharedInstance;}


查看完整回答
反對 回復(fù) 2019-08-06
?
回首憶惘然

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個贊

如果你想根據(jù)需要創(chuàng)建其他實(shí)例。這個:

+ (MyClass *)sharedInstance{
    static MyClass *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[MyClass alloc] init];
        // Do any other initialisation stuff here
    });
    return sharedInstance;}

否則,你應(yīng)該這樣做:

+ (id)allocWithZone:(NSZone *)zone{
    static MyClass *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [super allocWithZone:zone];
    });
    return sharedInstance;}


查看完整回答
反對 回復(fù) 2019-08-06
?
吃雞游戲

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個贊

這是ARC和非ARC的版本

如何使用:

MySingletonClass.h

@interface MySingletonClass : NSObject+(MySingletonClass *)sharedInstance;@end

MySingletonClass.m

#import "MySingletonClass.h"#import "SynthesizeSingleton.h"@implementation MySingletonClassSYNTHESIZE_SINGLETON_FOR_CLASS(MySingletonClass)@end


查看完整回答
反對 回復(fù) 2019-08-06
  • 3 回答
  • 0 關(guān)注
  • 584 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號