• 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: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning


  • Subject: Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning
  • From: "Chris Suter" <email@hidden>
  • Date: Tue, 14 Oct 2008 22:11:18 +1100

On Tue, Oct 14, 2008 at 9:13 PM, Graham Cox <email@hidden> wrote:

> Isn't the problem here with the init method, rather than alloc?

It's a problem with both.

> NSString et. al. return id because they are class clusters (and because it's the
> established convention),

I believe the fact that they are class clusters is irrelevant; it's an
implementation detail. The objects returned still conform to the
interfaces defined by NSString and NSMutableString. They return id,
rather than NSString say, because otherwise you'd get a compiler
warning if you tried to do something like:

    NSMutableString *string = [NSMutableString string];

> but for your own classes, you could define your
> init... method to return the specific object type.

You can't override the type for existing methods. For example,
initWithString: always returns an id. You can define them as returning
something different but the compiler will ignore it.

> Best solution is just not to make the methods look the same.

That's not always convenient. For example, it's nice to be able to do
[NSString initWithString:] and [NSMutableString initWithString:].

-- Chris
_______________________________________________

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: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning
      • From: John Engelhart <email@hidden>
    • Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning
      • From: Graham Cox <email@hidden>
References: 
 >[Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning (From: "Oleg Krupnov" <email@hidden>)
 >Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning (From: "Chris Suter" <email@hidden>)
 >Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning (From: "Oleg Krupnov" <email@hidden>)
 >Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning (From: "Chris Suter" <email@hidden>)
 >Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning
  • Next by Date: Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning
  • Previous by thread: Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning
  • Next by thread: Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning
  • Index(es):
    • Date
    • Thread