Unable to set NSXMLParser delegate to self
Asked Answered
A

2

6

I'm trying to create an NSXMLParser and call its delegate methods. On setting the delegate to self (2nd line below) I get a warning Sending 'XMLParserViewController *' to a parameter of incompatible type 'id <NSXMLParserDelegate>'. What am I missing here?

NSXMLParser *parser = [[NSXMLParser alloc]initWithData:data];
[parser setDelegate:self];
[parser parse];
[parser release];
Anitaanitra answered 26/5, 2011 at 15:39 Comment(1)
Does your XMLParserViewController class conform to the NSXMLParserDelegate protocol (in the interface)?You
B
24

Change the line: @interface XMLParserViewController : UIViewController (in your .h file) to:

@interface XMLParserViewController : UIViewController <NSXMLParserDelegate>

You forgot to set your UIViewController as a delegate of the delegate (if you will).

Bernina answered 26/5, 2011 at 15:41 Comment(1)
+1 For using correct class name and being slightly quicker than me.Chen
C
5

In the declaration of self you should have:

@interface YourClass <NSXMLParserDelegate>

to let the compiler know that your class conforms to the NSXMLParserDelegate protocol.

Chen answered 26/5, 2011 at 15:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.