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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM