简体   繁体   中英

How to set Parser Delegate to Self in ARC environment?

Hey I have used parsers in the past but never in an ARC environment. Now when I try and set my parser to self it gives me an error message and then doesn't parse my data. Anyone know what the problem is and how to solve it?

Here is the warning I get when I try to set the parser delegate to self:

Semantic Issue: Sending 'CharityController *const __strong' to parameter of incompatible    type 'id<NSXMLParserDelegate>'

Here is my code:

- (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;
    }

Did you use the protocol name in the interface definition to let the compiler know you conform to that particular protocol? Such as:

@interface CharityClass : NSObject <NSXMLParserDelegate>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM