I am pulling my hair out over a silly Xcode warning...

Discussion in 'Mac Programming' started by Nutter, Feb 27, 2007.

  1. macrumors 6502

    Mar 31, 2005
    London, England
    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.
  2. macrumors 68030


    Apr 17, 2004
    I think its a problem with [NSDictionary dictionary], not sure I'll post when I find out more information
  3. macrumors 601


    Jan 6, 2004
    Western US
    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:
  4. macrumors 603


    Aug 2, 2002
    Cork, Ireland.
    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.
  5. thread starter macrumors 6502

    Mar 31, 2005
    London, England
    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.

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

    Thanks guys.

Share This Page