objective-c - 使用为 ARC 配置的 XMLRPC 库,收到 ARC 错误

标签 objective-c ios automatic-ref-counting

我正在使用XMLRPC library旨在处理 ARC 和非 ARC 项目。当我尝试向它传递 NSError 对象时,我收到错误:

Implicit conversion of an Objective-C point to 'NSError *_autoreleasing *' is disallowed with ARC

和警告:

Incompatible point types sending 'NSError *_strong' to parameter of type 'NSError *_autoreleasing *'

方法如下:

+ (XMLRPCResponse *)sendSynchronousXMLRPCRequest: (XMLRPCRequest *)request error: (NSError **)error {
    NSHTTPURLResponse *response = nil;
#if ! __has_feature(objc_arc)
    NSData *data = [[[NSURLConnection sendSynchronousRequest: [request request] returningResponse: &response error: error] retain] autorelease];
#else
    NSData *data = [NSURLConnection sendSynchronousRequest: [request request] returningResponse: &response error: error];
#endif

    if (response) {
        NSInteger statusCode = [response statusCode];

        if ((statusCode < 400) && data) {
#if ! __has_feature(objc_arc)
            return [[[XMLRPCResponse alloc] initWithData: data] autorelease];
#else
            return [[XMLRPCResponse alloc] initWithData: data];
#endif
        }
    }

    return nil;
}

这是我尝试调用它的方法:

NSError *myError;

XMLRPCResponse *serverResponse = [XMLRPCConnection sendSynchronousXMLRPCRequest:request error:myError];

我想我不熟悉

#if

语法,但我猜它的行为就像常规的 If 语句一样?

我还启用了 ARC:

enter image description here

我是否应该重做 XMLRPCResponse 方法以删除对非 ARC 项目的处理,或者我收到错误/警告是否有原因?

最佳答案

在这里看看这个答案:

How do I know whether the compiler has ARC support enabled?

你用的是什么编译器?它可能不支持 __has_feature

关于错误..您应该执行以下操作:

NSError *error = nil;
XMLRPCResponse *serverResponse = [XMLRPCConnection sendSynchronousXMLRPCRequest:request error:&error];

因为该方法采用双指针作为错误参数。

关于objective-c - 使用为 ARC 配置的 XMLRPC 库,收到 ARC 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13311434/

相关文章:

iphone - 如何用Cocos2d-iPhone画线

iphone - 无法让 UITextField 自动收缩文本

ios - 在 iOS 中获取 BOX 的共享链接(文件链接)

ios - iTunes Connect 版本控制

iphone - 通过 View Controller 切换时应用程序崩溃

ios - GCDAsyncSocket 委托(delegate)调用不起作用

ios - 唤醒应用程序时重新加载单个 ViewController

ios - 如何将 CososDenshion 添加到支持 ARC 的 iPhone 应用程序中?

ios - 从后台返回后崩溃

objective-c - 样式 UIButtons - 子类?