PDA

View Full Version : I am pulling my hair out over a silly Xcode warning...




Nutter
Feb 27, 2007, 01:16 PM
This is driving me mad!

I have a class called RQiTunesItem with three init methods:


- (id)initWithAttributes:(NSDictionary *)attributes appleScriptObject:(MBAppleScriptObject *)appleScriptObject error:(NSError **)outError; // Designated initialiser
- (id)initWithAppleScriptObject:(MBAppleScriptObject *)appleScriptObject error:(NSError **)outError;
- (id)initWithAttributes:(NSDictionary *)attributes;


The first two methods work fine, but if I add a call to the third one and compile I get a warning from Xcode which says "warning: passing argument 1 of 'initWithAttributes:' from incompatible pointer type".

Here's an example of the call:


RQiTunesItem *item = [[RQiTunesItem alloc] initWithAttributes:[NSDictionary dictionary]];


If I go ahead and run the app it seems to work absolutely fine. initWithAttributes: does get called, and the object is initialised as it should be.

The really odd thing is that if I change the name of this method, for example calling it initWithFunkyAttributes:, the warning goes away. This leads me to believe that there is some kind of naming conflict going on between this method and the longer but similarly named initWithAttributes:appleScriptObject:error:. But how could this be??

Any help from programmers or psychiatrists much appreciated.



slooksterPSV
Feb 27, 2007, 01:53 PM
I think its a problem with [NSDictionary dictionary], not sure I'll post when I find out more information

HiRez
Feb 27, 2007, 02:25 PM
I've gotten those types of warnings when I write methods that conflict with ANY Apple API methods, it's really annoying. Why it can't understand that this method belongs to my class, I don't know. Just rename it something else that you know will be safe, like -initWithITunesItem:

whooleytoo
Feb 27, 2007, 02:40 PM
Presumably, the alloc method is returning a pointer of type "id", hence the confusion over which initWithAttributes: method is appropriate.

If this warning really bugs you, you can cast the pointer returned by alloc to RQiTunesItem* before calling the initWithAttributes: method.

Nutter
Feb 27, 2007, 02:46 PM
I've gotten those types of warnings when I write methods that conflict with ANY Apple API methods, it's really annoying. Why it can't understand that this method belongs to my class, I don't know. Just rename it something else that you know will be safe, like -initWithITunesItem:

Wow. So, because of a method called initWithAttributes: on NSOpenGLPixelFormat, Xcode complains? That is pretty irritating!

I guess I don't have to change the name of the method as long as I'm happy to ignore the warning.

Presumably, the alloc method is returning a pointer of type "id", hence the confusion over which initWithAttributes: method is appropriate.

Ah, I see why it's happening now. That does make sense, although it's still irritating!

Thanks guys.