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