首页 > OC中创建类的单实例方法所遇到的问题

OC中创建类的单实例方法所遇到的问题

创建一个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方法,这二者不会造成循环吗?该如何理解呢?


第一个方法调用的是父类的allocWithZone

【热门文章】
【热门文章】