xcode arc 下使用 block警告 Capturing [an object] strongly in this block is likely to lead to a retain cycle” in ARC-enabled code

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];

 

参考:http://stackoverflow.com/questions/7205128/fix-warning-capturing-an-object-strongly-in-this-block-is-likely-to-lead-to-a

posted @ 2014-01-15 15:40  cocoajin  阅读(4257)  评论(0编辑  收藏  举报