ios NSErrortypes

自从我添加了这个asynchronous请求,我得到一个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然后我的代码运行良好,但我不觉得不使用错误..我该怎么办?

推测这是因为你正在重用在完成处理程序中传递给你的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]; ... }); }]; ... 

这个Xcode错误发生时,把NSError *error=nil; ^块的定义。

在块内,然后error:&error工作正常。