Replying to myself:
My understanding of the documentation says that using keyword block
and setting the variable to nil after using it inside the block should be ok, but it still shows the warning.
__block ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:...
[request setCompletionBlock:^{
NSDictionary *jsonDictionary = [[CJSONDeserializer deserializer] deserialize:request.responseData error:nil];
request = nil;
// ....
}];
Update: got it to work with the keyword '_weak' instead of '_block', and using a temporary variable:
ASIHTTPRequest *_request = [[ASIHTTPRequest alloc] initWithURL:...
__weak ASIHTTPRequest *request = _request;
[request setCompletionBlock:^{
NSDictionary *jsonDictionary = [[CJSONDeserializer deserializer] deserialize:request.responseData error:nil];
// ...
}];
If you want to also target iOS 4, use __unsafe_unretained
instead of __weak
. Same behavior, but the pointer stays dangling instead of being automatically set to nil when the object is destroyed.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…