• 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: Sending the "value" message to an object typed "id"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sending the "value" message to an object typed "id"


  • Subject: Re: Sending the "value" message to an object typed "id"
  • From: Graham Cox <email@hidden>
  • Date: Mon, 7 Sep 2009 22:11:56 +1000


On 07/09/2009, at 9:36 PM, Paulo F. Andrade wrote:

So what's the deal with the method name "value" and ObjC runtime?


As an iPhone question this may be incorrect, but normally you use - floatValue to get a, umm, float value.

I suspect what's occurring is that -value is defined in multiple classes having different return types: maybe float in one case and id in another, say. The compiler can't disambiguate a method based on return type alone so compiles based solely on the first one it encounters, which to all intents and purposes may as well be random. It's a dirty little secret of Obj-C (or at least the current compilers) and is a very real source of bugs (and sometimes quite dangerous ones at that).

To avoid it, where possible do not use type id and always use explicit types if you can. If you know your sender is a UISlider*, then cast to that when messaging it with method names that can be ambiguous. Short and vague method names like -value are fairly likely to be ambiguous.

--Graham


_______________________________________________

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: Sending the "value" message to an object typed "id"
      • From: Jens Alfke <email@hidden>
    • Re: Sending the "value" message to an object typed "id"
      • From: "Paulo F. Andrade" <email@hidden>
References: 
 >Sending the "value" message to an object typed "id" (From: "Paulo F. Andrade" <email@hidden>)

  • Prev by Date: Re: Turn on zombies in user environment?
  • Next by Date: Re: Turn on zombies in user environment?
  • Previous by thread: Sending the "value" message to an object typed "id"
  • Next by thread: Re: Sending the "value" message to an object typed "id"
  • Index(es):
    • Date
    • Thread