objective-c - OC中创建类的单实例方法所遇到的问题
巴扎黑
巴扎黑 2017-04-24 09:11:40
0
1
308

创建一个BNRitemStore类的单实例

+(BNRitemStore *)sharedStore{
    static BNRitemStore *sharedStore = nil;
    if(!sharedStore){
        sharedStore = [[super allocWithZone:nil]init];
    }
    return sharedStore;
}

+(id)allocWithZone:(NSZone *)zone{
    return [self sharedStore];
   }

第一个方法中使用了allocWithZone方法,第二个方法中又使用了sharedStore方法,这二者不会造成循环吗?该如何理解呢?

巴扎黑
巴扎黑

membalas semua(1)
大家讲道理

Kaedah pertama memanggil allocWithZone kelas induk

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan