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];
NSExplorer
  • 11,849
  • 12
  • 49
  • 62
  • 1
    Does your `XMLParserViewController` class conform to the `NSXMLParserDelegate` protocol (in the interface)? –  May 26 '11 at 15:41

2 Answers2

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

max_
  • 24,076
  • 39
  • 122
  • 211
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.

Erik B
  • 40,889
  • 25
  • 119
  • 135