使用为ARC配置的XMLRPC库,会出现ARC错误

时间:2012-11-09 15:56:32

标签: objective-c ios automatic-ref-counting

我正在使用设置来处理ARC和非ARC项目的XMLRPC library。当我尝试传递一个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项目的处理,还是有理由我收到错误/警告?

1 个答案:

答案 0 :(得分:1)

在这里看看这个答案:

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

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

关于错误..你应该采取以下措施:

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

由于该方法采用了错误参数的双指针。