• 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: style question: when to use 'id' as return value?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: style question: when to use 'id' as return value?


  • Subject: Re: style question: when to use 'id' as return value?
  • From: "Sean McBride" <email@hidden>
  • Date: Mon, 17 Dec 2007 17:36:04 -0500
  • Organization: Rogue Research

On 12/17/07 2:25 PM, Bill Bumgarner said:

>On Dec 17, 2007, at 2:14 PM, Sean McBride wrote:
>> NSString has the method:
>>
>> + (id)stringWithString:(NSString *)aString
>>
>> Why is the return value not an 'NSString*' instead of an 'id'?  Is
>> this
>> just a stylistic preference, or...?
>
>Because both NSString and NSMutableString Do The Right Thing when that
>method is invoked and, thus, declaring that the method returns a
>particular type of string -- mutable or immutable -- would be wrong
>half the time.

I see; makes sense, thanks!  But this was just one example, there are
other situations where I don't understand how 'id' was chosen over a
concrete type.  For example:

+ (id)sharedGlyphGenerator

 vs

+ (ABAddressBook *)sharedAddressBook

Likewise, why does NSWindow's -windowController return 'id' and not
'NSWindowController*'?

I'm trying to understand in general...

Cheers,

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada

_______________________________________________

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: style question: when to use 'id' as return value?
      • From: j o a r <email@hidden>
    • Re: style question: when to use 'id' as return value?
      • From: Chris Suter <email@hidden>
References: 
 >style question: when to use 'id' as return value? (From: "Sean McBride" <email@hidden>)
 >Re: style question: when to use 'id' as return value? (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: style question: when to use 'id' as return value?
  • Next by Date: Re: How do I get NSRect to be the same as CGRect?
  • Previous by thread: Re: style question: when to use 'id' as return value?
  • Next by thread: Re: style question: when to use 'id' as return value?
  • Index(es):
    • Date
    • Thread