自从我添加了这个异步请求后,我得到了一个Sending 'NSError *const __strong *' to parameter of type 'NSError *__autoreleasing *' changes retain/release properties of pointer的xcode错误
...
[NSURLConnection sendAsynchronousRequest:req queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLData:data error:&error];
...
});
}];
...如果我使用error:nil,那么我的代码运行良好,但我对不使用错误感到不安。我该怎么办?
发布于 2012-02-08 23:58:12
这大概是因为您在重用在完成处理程序中传递给您的error。它将作为__strong传递,然后将它传递到需要为__autoreleasing的位置。尝试更改为以下代码:
...
[NSURLConnection sendAsynchronousRequest:req queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
dispatch_async(dispatch_get_main_queue(), ^{
NSError *error2 = nil;
NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLData:data error:&error2];
...
});
}];
...发布于 2015-12-17 11:45:02
当将NSError *error=nil;定义放在^块的之外时,就会发生这个Xcode错误。
在这个块中,error:&error工作得很好。
https://stackoverflow.com/questions/9203044
复制相似问题