Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to set NSXMLParser delegate to self

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];
like image 818
NSExplorer Avatar asked May 26 '11 15:05

NSExplorer


2 Answers

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).

like image 65
max_ Avatar answered Oct 06 '22 00:10

max_


In the declaration of self you should have:

@interface YourClass <NSXMLParserDelegate>

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

like image 23
Erik B Avatar answered Oct 05 '22 23:10

Erik B