Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为什么NSMutableArray在init类中allo init自动释放时总是出错?_Iphone_Xcode_Nsmutablearray - Fatal编程技术网

Iphone 为什么NSMutableArray在init类中allo init自动释放时总是出错?

Iphone 为什么NSMutableArray在init类中allo init自动释放时总是出错?,iphone,xcode,nsmutablearray,Iphone,Xcode,Nsmutablearray,我把它放在某处 @property (nonatomic, retain) NSMutableArray * BusinessQueue; -(BNUtilitiesQuick *) init { if (!(self = [super init])) { return nil; }//if the superclass is NSObject, this must be init self.locatio

我把它放在某处

@property (nonatomic, retain) NSMutableArray * BusinessQueue;

-(BNUtilitiesQuick *) init {
        if (!(self = [super init]))
        {
            return nil;
        }//if the superclass is NSObject, this must be init
        self.locationManager = [[[CLLocationManager alloc] init]autorelease];
        BusinessQueue = [[[NSMutableArray alloc]init]autorelease]; 
        return self; //and return the object itself
    }
在我看来,BusinessQueue=[[NSMutableArray alloc]init]autorelease]将使引用计数为1。1为alloc-1表示自动释放(有时是后者),1表示业务队列是保留属性

然而,BusinessQueue有时通常会被释放

为什么BusinessQueue总是出错,而location manager却不出错


有错误代码吗?或者NSMutableArray不能在init类中声明?

BusinessQueue
不是属性
self.BusinessQueue
可能是,如果您这样定义的话

补充: 进行初始化的最佳/最简单的方法是:

self.businessQueue = [NSMutableArray array];

BusinessQueue
不是属性
self.BusinessQueue
可能是,如果您这样定义的话

补充: 进行初始化的最佳/最简单的方法是:

self.businessQueue = [NSMutableArray array];

您是否将函数放在.h标题中?你喜欢排队吗?它不用于以大写字母try self开头的变量。BusinessQueue=[NSMutableArray];至少您已经在属性中保留了BusinessQueue。您是否将该函数放在了.h头中?你喜欢排队吗?它不用于以大写字母try self开头的变量。BusinessQueue=[NSMutableArray];至少你已经在酒店里保留了BusinessQueue这是我注意到的另一件事。有时我可以称之为没有自我的财产。隐马尔可夫模型。。。如果我只做BusinessQueue,那么它就是直接分配变量而不保留。当你在对象中引用一个字段而没有“self”时,你指的是字段,而不是属性。这是不同的。该字段只是--不调用代码,直接引用它。该属性后面有setter和getter方法,如果有指示,它们会执行
retain
。这是我注意到的另一件事。有时我可以称之为没有自我的财产。隐马尔可夫模型。。。如果我只做BusinessQueue,那么它就是直接分配变量而不保留。当你在对象中引用一个字段而没有“self”时,你指的是字段,而不是属性。这是不同的。该字段只是--不调用代码,直接引用它。该属性后面有setter和getter方法,如果有指示,它们将执行
保留