Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nutter

macrumors 6502
Original poster
Mar 31, 2005
432
0
London, England
This is driving me mad!

I have a class called RQiTunesItem with three init methods:

Code:
- (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:

Code:
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.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
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:
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
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.
 

Nutter

macrumors 6502
Original poster
Mar 31, 2005
432
0
London, England
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.