objective-c - 警告 ASIHttpRequest

标签 objective-c ios

我在我的 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/

相关文章:

ios - UICollectionView 使用不同高度的单元格

ios - UINavigationController 和 UIViewController 的导航 Controller 属性

iphone - 如何使用终端将 .p12 文件转换为 .pem 文件?

ios - 从不同时区的日期选择器获取日期

ios - 谷歌地图 sdk ios Api 错误

ios - 如何通过编程创建的导航 Controller POP 查看 Controller

iphone - UINavigationController:如何管理取消按钮和后退按钮

IOS TableView 第一个单元格图像应该从状态栏开始

iphone - 使用CLLocationCoordinate2D获取当前位置

ios - 获取相对于 SKEffectNode 屏幕的绝对位置,因为它被 SKWarpGeometryGrid 扭曲