Unable to configure NSXMLParser delegate by itself

I am trying to create NSXMLParser and call its delegation methods. When setting the delegate to itself (second line below) I get the 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]; 
+6
source share
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 delegate (if you want).

+24
source

In declaring yourself you must:

 @interface YourClass <NSXMLParserDelegate> 

so that the compiler knows that your class complies with the NSXMLParserDelegate protocol.

+5
source

Source: https://habr.com/ru/post/889128/


All Articles