• 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: j o a r <email@hidden>
  • Date: Mon, 17 Dec 2007 14:58:34 -0800


On Dec 17, 2007, at 2:36 PM, Sean McBride wrote:

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


I would use this pattern:

* Returning properties of an instance ("-windowController") or of a class ("+sharedAddressBook")
-> Use the actual type


* Returning new instances from an init method ("-initWithString:"), or a class factory method ("+stringWithString:")
-> Use "id"


(But as you have noted, Cocoa apparently doesn't agree with me completely)

There probably should be some official documentation and guidelines for this, but I don't think there currently is?

j o a r


_______________________________________________

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


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>)
 >Re: style question: when to use 'id' as return value? (From: "Sean McBride" <email@hidden>)

  • Prev by Date: Re: style question: when to use 'id' as return value?
  • Next by Date: Re: style question: when to use 'id' as return value?
  • Previous by thread: Re: style question: when to use 'id' as return value?
  • Next by thread: setWantsLayer causes text fields to draw focus ring incorrectly
  • Index(es):
    • Date
    • Thread