IOS types NSError

Since I added this asynchronous request, I get xcode error 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 works fine, but I feel awkward about not using errors .. What should I do?

+5
source share
2 answers

Presumably, this is because you are reusing the errorone passed to you in the completion handler. It will be transferred as __strong, and then you will transfer it where required __autoreleasing. Try switching 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];
        ...
    });
}];
...
+11
source

This Xcode error occurs when putting a NSError *error=nil;definition outside the ^ block.

It error:&errorworks fine inside the unit .

+2

All Articles