2012-02-08 12 views
5

Da quando ho aggiunto questa richiesta asincrono, sto ricevendo un errore di Xcode Sending 'NSError *const __strong *' to parameter of type 'NSError *__autoreleasing *' changes retain/release properties of pointertipi ios NSError

... 
[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]; 
     ... 
    }); 
}]; 
... 

Se uso allora il mio codice funziona benissimo, ma mi sento a disagio di non usando gli errori .. Cosa dovrei fare?

+0

Se in realtà non stai facendo nulla con l'errore potresti anche passare NULL. Di solito è possibile rilevare se si è verificato un errore in ogni caso perché il metodo restituisce zero, quindi non è che ti manchi il fatto che gli errori stanno accadendo. –

risposta

11

Presumibilmente è perché si sta riutilizzando il error passato al gestore di completamento. Verrà passato come __strong e quindi lo si passa dove è richiesto che sia __autoreleasing. Provare a cambiare a questo codice:

errore
... 
[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]; 
     ... 
    }); 
}]; 
... 
2

Questo accade quando Xcode mettere NSError *error=nil; definizione al di fuori del blocco ^.

All'interno del blocco, quindi error:&error funziona correttamente.

Problemi correlati