简体   繁体   中英

Getting an ARC warning for capturing an ojbect strongly

I'm using ARC and getting a warning saying Capturing 'request' strongly in this block is likely to a retain cycle.

__block ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];
[request setCompletionBlock:^{
        NSString *responseString = [request responseString];
        self.appointmentArray = [responseString JSONValue];
    }];
    [request setFailedBlock:^{
        NSError *error = [request error];
        NSLog(@"%@", error.description);
    }];

I'm assuming request is declared somewhere before the blocks. You need to declare it as __weak , or set a second, weakly-declared variable to it.

This question is similar. Try this:

__block ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];
__weak ASIHTTPRequest *request_b = request;
[request setCompletionBlock:^{
    NSString *responseString = [request_b responseString];
    self.appointmentArray = [responseString JSONValue];
}];
[request setFailedBlock:^{
    NSError *error = [request_b error];
    NSLog(@"%@", error.description);
}];

Simply replacing:
__block ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];

with:
__weak ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];

will suffice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM