Ever since I added this async request, I'm getting an xcode error of 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];
...
});
}];
...
If I use error:nil
then my code runs fine, but I feel uneasy about not using errors.. What should I do?
Presumably it's because you're reusing the error
passed in to you in the completion handler. It'll be being passed as __strong
and then you pass it in where it is required to be __autoreleasing
. Try changing to this code:
...
[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];
...
});
}];
...
This Xcode error happens when put NSError *error=nil;
definition outside the ^block.
Inside the block, then error:&error
works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With