AFNetworking 2.0 iOS 7中AFHTTPRequestOperation.h文件出现“Copy with zone warning”警告

3
在Xcode 5的AFNetworking 2.x版本中,我不断收到有关此方法的警告。
AFHTTPRequestOperation *operation = [[[self class] allocWithZone:zone] initWithRequest:self.request];

self.request是不兼容的指针类型,将'NSURLRequest *'发送到类型为'MKLocalSearchRequest *'的参数。

#pragma mark - NSCopying

- (id)copyWithZone:(NSZone *)zone {
    AFHTTPRequestOperation *operation = [[[self class] allocWithZone:zone] initWithRequest:self.request];

    operation.responseSerializer = [self.responseSerializer copyWithZone:zone];
    operation.completionQueue = self.completionQueue;
    operation.completionGroup = self.completionGroup;

    return operation;
}

有人解决了这个问题(警告)吗?


2
这个主题最近有一个相关的问题在这里开启:https://github.com/AFNetworking/AFNetworking/issues/1806 - Aaron Brager
1个回答

3
问题在于[self class]返回的是一个未确定类型的Class对象。编译器将-initWithRequest:方法与MapKit中的方法匹配。可以通过更改代码来解决这个问题:
AFHTTPRequestOperation *operation = [(AFHTTPRequestOperation *)[[self class] allocWithZone:zone] initWithRequest:self.request];

太好了,Neal通过类型转换解决了这个问题。我也想到了这一点,但我在AFNetworking方面还很新,所以最好询问建议。 - hardikdevios

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接