• 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
Re: Why can't I name a property `tag'?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why can't I name a property `tag'?


  • Subject: Re: Why can't I name a property `tag'?
  • From: Brian Stern <email@hidden>
  • Date: Thu, 10 Jul 2008 14:17:25 -0400


On Jul 10, 2008, at 12:44 PM, Michael Ash wrote:

On Thu, Jul 10, 2008 at 9:49 AM, an0 <email@hidden> wrote:
Thanks. But isn't it annoying for XCode to pretend to know something
for sure while in fact it is just a wrong guess? At least the warning
is very misleading.

The warning isn't misleading at all. Xcode is not pretending anything. It *does* know it for sure, it's just *wrong*. The warning then appears because this wrong information causes other problems in the code later on, due to a mismatched type.

The compiler definitely should complain if it has two methods with the
same name but different return types to choose from, and it doesn't
know which one is right. I've seen it happen many times. If it didn't
happen to you, it's because either it wasn't seeing one of them, or
because you found a compiler bug.

This is an inherent hazard of using the "id" type. For best results,
you should avoid using any method name which is already in use unless
your return type is compatible with the one already in use.

Mike

Actually this problem extends not only to return types but also parameter types. So if one has a class like this:


@interface MyDocument : NSDocument{
}
- (id)initWithData:(int)inData;
@end

And you try to build one:

MyDocument*		doc = [[MyDocument alloc] initWithData:0];

You will receive an error: "incompatible type for argument 1 of 'initWithData:";

The problem of course is that alloc returns an id and gcc's method matching is finding a different declaration of initWithData in the Cocoa headers for another class.

So I would add "For best results, you should avoid using any method name that is already in use unless its return type and parameters are identical with the already existing method."

Obviously there is some potential for new versions of Cocoa to add new methods that conflict with your own methods.

--
Brian Stern
email@hidden



_______________________________________________

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: Why can't I name a property `tag'?
      • From: "Michael Ash" <email@hidden>
References: 
 >Why can't I name a property `tag'? (From: an0 <email@hidden>)
 >Re: Why can't I name a property `tag'? (From: Graham Cox <email@hidden>)
 >Re: Why can't I name a property `tag'? (From: an0 <email@hidden>)
 >Re: Why can't I name a property `tag'? (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: Why can't I name a property `tag'?
  • Next by Date: I cannot add a (system) framework to a Cocoa Application
  • Previous by thread: Re: Why can't I name a property `tag'?
  • Next by thread: Re: Why can't I name a property `tag'?
  • Index(es):
    • Date
    • Thread