gpt4 book ai didi

objective-c - 警告 ASIHttpRequest

转载 作者:行者123 更新时间:2023-11-29 13:38:27 26 4
gpt4 key购买 nike

我在我的 iOS 应用程序中使用 ASIHTTPRequest。我这样做:.h

@interface MyClassr
ASIFormDataRequest *currentRequest;
}

NSURL *url = [NSURL URLWithString:requestUrl];
currentRequest = [ASIFormDataRequest requestWithURL:url];
currentRequest.requestMethod=@"GET";
currentRequest.delegate =self;

[currentRequest setCompletionBlock:^{
listesRestaurants = [XMLParser parseRestaurantResponse:[currentRequest responseData]];
NSLog(@"%@",[currentRequest responseString]);
if (apDelegate.modeGeoloc) {
[map removeAnnotations:map.annotations];
[self addAnnotation];
[self calculDistance];
}

我在行中有一个警告:[currentRequest setCompletionBlock:^//Block will be retained by an object strongly retained by the captured object

//在此 block 中强烈捕获'self'很可能导致保留循环

请问我该如何纠正这个警告?

最佳答案

您需要创建对自身的弱引用:

__weak MyClassr* blockSelf = self;

然后在您的 block 中使用该引用:

[blockSelf addAnnotation];
[blockSelf caculDistance];

等等

关于objective-c - 警告 ASIHttpRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9909830/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com