5

When I declare appDelegate interface as follows in order to set NSXMLParserDelegate, I receive some warnings from other views that are using [[UIApplication sharedApplication] delegate];

@interface AppDelegate : UIResponder <UIApplicationDelegate, NSXMLParserDelegate>

warning: Initializing 'AppDelegate *__strong' with an expression of incompatible type 'id'

However, if I remove it, another warning appears due to self setting of xmlParser,

@interface AppDelegate : UIResponder <UIApplicationDelegate>

warning: Sending 'AppDelegate *const __strong' to parameter of incompatible type 'id'

on

    xmlParser = [[NSXMLParser alloc] initWithData:receivedData];
    [xmlParser setDelegate:self];

How to remove both? thank you

Pfitz
  • 7,336
  • 4
  • 38
  • 51
Jaume
  • 3,672
  • 19
  • 60
  • 119
  • 1
    any chance you could put your xml parser in a different object (singleton or instantiated) that isn't the app delegate? – Michael Dautermann Jun 21 '12 at 21:51
  • @Michael, if I could start from zero yes but there is a lot of code to modify and finaly if not possible is just a warning and do not affect to app functionality – Jaume Jun 21 '12 at 21:57

1 Answers1

19

You really should not be making your AppDelegate publicly exposing interfaces. It creates very tight coupling between all your code. If other code (outside your AppDelegate) is needing an NSXMLParserDelegate you should make a different class for it.

It looks like your AppDelegate is needing to be a delegate for its own purposes. You can "privately" implement the interface by making a class extension in your AppDelegate.m file.

@interface AppDelegate() <NSXMLParserDelegate>
@end

Doing the above will remove the warning you received here:

[xmlParser setDelegate:self];
David V
  • 11,531
  • 5
  • 42
  • 66