I have a subclass of NSObject that implements a method -(id)initWithRootElement:(MyElement *)e. NSXMLDocument has an identical method that accepts NSXMLElement. When I compile, I get the following warning:
warning: incompatible Objective-C types 'struct MyElement *', expected 'struct NSXMLElement *' when passing argument 1 of 'initWithRootElement:' from distinct Objective-C type
In this case, I compile Clang + LLVM on SnowLeopard with Xcode 3.2.1, but this also happens with GCC 4.2 on Leopard and SnowLeopard.
I don’t understand why this throws a warning for my direct subclass of NSObject when NSXMLDocument must first inherit NSXMLNode? Shouldn't he know that he -(id)initWithRootElement:(NSXMLElement *)eapplies only to NSXMLDocument, which has nothing to do with my class? I could understand if I was trying to overload this method, but I do not know. Please tell me I'm not losing my mind ...
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSXMLElement.h>
typedef NSObject MyElement;
@interface TestClass : NSObject
{
}
- (id)initWithRootElement:(MyElement *)element;
@end
@implementation TestClass
- (id)initWithRootElement:(MyElement *)element { return nil; }
@end
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSXMLElement *xmlElement = [[NSXMLElement alloc] initWithName:@"foo"];
[[TestClass alloc] initWithRootElement:xmlElement];
MyElement *element = [[MyElement alloc] init];
[[TestClass alloc] initWithRootElement:element];
[pool drain];
return 0;
}