• 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
why does this method return an id?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

why does this method return an id?


  • Subject: why does this method return an id?
  • From: Matt Neuburg <email@hidden>
  • Date: Sun, 11 Dec 2011 08:58:38 -0800

There seems to be a small hole in my understanding of Objective-C. I sort of understand why alloc-init returns an id, but why do so many class method convenience instantiators also return an id? For example:

 [NSSortDescriptor sortDescriptorWithKey:@"indexOrig" ascending:YES]

That method is declared as returning an id, which means you can use it accidentally anywhere, assign the result to the wrong thing, and get a mysterious crash. (Guess how I know that?) Now, I think I know why [NSString string] is declared as returning an id - it's because it's a class cluster, right? But NSSortDescriptor isn't a class cluster; the result really is an NSSortDescriptor. So why isn't it *declared* as an NSSortDescriptor? Thx - m.

--
matt neuburg, phd = email@hidden, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
Programming iOS 4! http://www.apeth.net/matt/default.html#iosbook
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com


_______________________________________________

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 does this method return an id?
      • From: Ben Kennedy <email@hidden>
    • Re: why does this method return an id?
      • From: Fritz Anderson <email@hidden>
    • Re: why does this method return an id?
      • From: Charles Srstka <email@hidden>
  • Prev by Date: Re: Best way to manage double-clicked files?
  • Next by Date: Re: why does this method return an id?
  • Previous by thread: Re: NSComboBoxCell pop-up list showing
  • Next by thread: Re: why does this method return an id?
  • Index(es):
    • Date
    • Thread