xcode arc 下使用 block警告 Capturing [an object] strongly in this block is likely to lead to a retain cycle” in ARC-enabled code
解决方法:
方法一:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:Api]]; __block ASIHTTPRequest *brRequest = request; [request setCompletionBlock:^{ id json = [NSJSONSerialization JSONObjectWithData:[brRequest responseData] options:0 error:Nil]; //NSLog(@"%@",json); NSLog(@"completed"); }]; [request setFailedBlock:^{ NSLog(@"%@",[brRequest error]); }]; [request startAsynchronous];
方法2:
// //方式二 // __weak ASIHTTPRequest *werRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:api]]; // [werRequest setCompletionBlock:^{ // id json = [NSJSONSerialization JSONObjectWithData:[werRequest responseData] options:0 error:Nil]; // NSLog(@"%@",json); // // }]; // // [werRequest setFailedBlock:^{ // NSLog(@"%@",[werRequest error]); // }]; // // [werRequest startAsynchronous];