ios NSError类型 [英] ios NSError types

查看:47
本文介绍了ios NSError类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我添加了这个 async 请求以来,我收到的xcode错误是将'NSError * const __strong *'发送给类型为'NSError * __ autoreleasing *'的参数,更改保留/释放指针的属性

Ever since I added this async request, I'm getting an xcode error of Sending 'NSError *const __strong *' to parameter of type 'NSError *__autoreleasing *' changes retain/release properties of pointer

...
[NSURLConnection sendAsynchronousRequest:req queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
    dispatch_async(dispatch_get_main_queue(), ^{
        NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLData:data error:&error];
        ...
    });
}];
...

如果我使用 error:nil ,则我的代码可以正常运行,但是对于不使用错误,我感到不安.我该怎么办?

If I use error:nil then my code runs fine, but I feel uneasy about not using errors.. What should I do?

推荐答案

大概是因为您正在重用在完成处理程序中传递给您的 error .它会以 __ strong 的形式传递,然后在需要 __ autoreleasing 的位置传递它.尝试更改为以下代码:

Presumably it's because you're reusing the error passed in to you in the completion handler. It'll be being passed as __strong and then you pass it in where it is required to be __autoreleasing. Try changing to this code:

...
[NSURLConnection sendAsynchronousRequest:req queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
    dispatch_async(dispatch_get_main_queue(), ^{
        NSError *error2 = nil;
        NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLData:data error:&error2];
        ...
    });
}];
...

这篇关于ios NSError类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆