我正在使用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:
我是否应该重做 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/