自从我添加了此异步请求后,我的xcode错误为Sending 'NSError *const __strong *' to parameter of type 'NSError *__autoreleasing *' changes retain/release properties of pointer
...
[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
,那么我的代码运行正常,但我觉得不安关于不使用错误。我该怎么办?
答案 0 :(得分:11)
大概是因为你在重启处理程序中重用了传递给你的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];
...
});
}];
...
答案 1 :(得分:2)
将error:&error
定义置于 ^块后,会出现此Xcode错误。
在块中,{{1}}正常工作。