简体   繁体   English

获取ARC警告以强烈捕获ojbect

[英]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. 我正在使用ARC并得到一个警告,说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. 我假设request是在块之前的某个地方声明的。 You need to declare it as __weak , or set a second, weakly-declared variable to it. 您需要将其声明为__weak ,或者为其设置第二个弱声明变量。

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]; __block ASIFormDataRequest * request = [[ASIFormDataRequest alloc] initWithURL:url];

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

will suffice. 就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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