嘿,我过去曾使用过解析器,但从未在ARC环境中使用过。现在,当我尝试将解析器设置为self时,它会给出一条错误消息,然后不会解析我的数据。任何人都知道问题是什么以及如何解决它?
以下是我尝试将解析器委托设置为self时收到的警告:
Semantic Issue: Sending 'CharityController *const __strong' to parameter of incompatible type 'id<NSXMLParserDelegate>'
这是我的代码:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
if (connection == theConnection)
{
// do something with the data object.
//NSLog(@"Data from server is: %@",data);
NSString *test = [[NSString alloc]initWithData:data encoding:NSStringEncodingConversionAllowLossy];
NSLog(@"Data from server is: %@",test);
parser = [[NSXMLParser alloc] initWithData: data];
[parser setDelegate:self];
[parser parse];
}
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"root"]) {
currentStringValue = nil;
NSLog(@"I am inside the Parser at root!.");
return;
}
答案 0 :(得分:7)
您是否在接口定义中使用协议名称让编译器知道您符合该特定协议?如:
@interface CharityClass : NSObject <NSXMLParserDelegate>