I would like to set the value of an NSData
object within my block. Can someone let me know what I have done wrong here?
// Data
__block NSData *data = nil;
[ZSURLConnection performRequestWithUrl:wsdlURL xmlString:xml completionHandler:^(NSData *response, NSError *error) {
// Handle the error
if (error) {
NSLog(@"Error: %@", [error localizedDescription]);
} else {
data = response;
}//end
}];//end block
if (data) {
NSString *d = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"DATA --- %@", d);
}
return data;
Why can't I assign the response to data
and then retrieve it outside of my block?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…