• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
multiple methods named 'xxx' found.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

multiple methods named 'xxx' found.


  • Subject: multiple methods named 'xxx' found.
  • From: Nelson Santos <email@hidden>
  • Date: Thu, 4 Oct 2007 21:12:43 -0400

Hi all,

I found the below thread messages on the Cocoabuilder site. Please have a quick look. I understand what YMMV is saying, but does anyone know the reason why that warning occurs? Wouldn't the fact that the two methods are defined in different classes enough to allow multiple methods with the same name and different arguments to exist? I am getting the same problem in my project but I quickly fixed it by renaming my method. I thought that was really odd.

Nelson









FROM : Ricky Sharp
DATE : Mon Sep 17 23:50:08 2007

On Sep 17, 2007, at 4:22 PM, Hans van der Meer wrote:

> In my code I have in a testcase:
> @interface HMCharacterAlphabetTest : SenTestCase {
> ...
> Inside one of the tests:
> HMCharacterAlphabet *alphabet = [[HMCharacterAlphabet alloc]
> initWithSize: 3];
> defined in class HMCharacterAlphabet as:
> - (id) initWithSize: (unsigned) size; // class in
> HMCharacterAlphabet.h
>
> Somehow arises confusion with the identically typed init in NSImage.h:
> - (id)initWithSize:(NSSize)aSize;
>
> Compiling gives:
> warning: multiple methods named -initWithSize
> error: incompatible type for argument 1 of initWithSize
> warning: using -(id)initWithSize:(NSSize)aSize (NSImage.h:65)
>
> I fail to see why this is possible, as these declarations are in
> different classes.
> Presumably it is some silly mistake. Can someone point me in the
> right direction?



I believe the issue here is that both initWithSize: methods are ultimately being sent to id.

I ran into a similar situation where one my custom control classes
had this:

- (int)currentValue
{
    return [[self cell] currentValue];
}

When 10.4 was introduced, NSAnimation added a -(float)currentValue
API.  The scary thing was that the code compiled.  At runtime, the
control actually sent NSAnimation's message instead!  This is because
[self cell] returns an id.  It then decided to send the animation's
message (probably since it was picked up first due to importing
<Cocoa/Cocoa.h> in my precomp header).

In your case, it looks like you do have -Wstrict-selector-match in
your 'Other C Flags' options.  That's a good thing (and other
developers should consider turning that one on to catch these
situations).

There are then two workarounds:

(A) explicit cast.  Not always good.  In my control's API, the
workaround would look like this:

return [(IIValueFieldCell*) [self cell] currentValue];

But, I decided to do (B) instead:


(B) Due to lack of namespacing, I made three key changes so that no collisions would ever occur:

(1) All class names, constants, globals, structs, typedefs prefixed
with II.  Most folks are doing this; picking a unique 2-letter prefix.

(2) Suffix all ivars with _II (which then gave me unique accessors).
For example:

BOOL checked_II;
-(BOOL)checked_II;
-(void)setChecked_II:(BOOL)flag;

I did the same thing for any custom bindings.

(3) Suffix all methods (before first arg) with _II:

- (int)computeSum_II
- (void)initWithStudent_II:(IIStudent*)aStudent
- (void)initWithStudentName_II:(NSString*)aName settings:(IISettings*)
someSettings;

messages are thus computeSum_II, initWithStudent_II: and
initWithStudentName_II:settings:


YMMV

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: multiple methods named 'xxx' found.
      • From: Charles Steinman <email@hidden>
  • Prev by Date: Re: How to have a shared integer variable in application
  • Next by Date: Re: Binding (KVC/KVO) for C struct datatypes
  • Previous by thread: Re: How to have a shared integer variable in application
  • Next by thread: Re: multiple methods named 'xxx' found.
  • Index(es):
    • Date
    • Thread