• 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: Strange property/synthesized accessor behaviour
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange property/synthesized accessor behaviour


  • Subject: Re: Strange property/synthesized accessor behaviour
  • From: Philipp Leusmann <email@hidden>
  • Date: Sun, 10 Apr 2011 14:45:12 +0200

In this situation XCode4 did not show a warning.

Philipp


Am 10.04.2011 um 13:44 schrieb Anders Norlander:

> You should get a warning about ambiguous messages, and it also tells you which selector is actually used:
> Multiple methods named 'width' found
> Using '-(CGFloat)width'
>
> Then use static typing to resolve the ambiguity (i.e [(Resolution*)object width])
> 'treat warnings as errors' is a big help in avoiding issues like this.
>
> -Anders
>
> On 2011-04-10, at 12:25 , Philipp Leusmann wrote:
>
>> Stephen,
>>
>> thanks to your detailed answer. This absolutely explains the observed behavior, but still leaves me wondering about the feature of sending messages to id.
>> While I am still new to programming in objective-c and only having read the basic language documentation, I remember this feature to be pointed out as a helpful tool. But after this discovery, I can only mark it as a "don't use" language feature.
>>
>> Regards,
>> Philipp
>>
>> Am 10.04.2011 um 10:00 schrieb Stephen J. Butler:
>>
>>> On Sat, Apr 9, 2011 at 9:52 AM, Philipp Leusmann <email@hidden> wrote:
>>>> Who can explain this behavior to me? Why is oWidth != object.mWidth ? How can that happen?
>>>
>>> It's an artifact of how Objective-C searches for selector
>>> implementations. You're calling @selector(width) on an "id", and of
>>> course "id" doesn't implement @selector(width).
>>>
>>> So what Objective-C does is search for the first implementation of
>>> @selector(width) that it finds. My guess is it finds the one in AppKit
>>> first (greping the frameworks):
>>>
>>> NSTableColumn.h:- (CGFloat)width;
>>>
>>> Then when the compiler sets up the call site it does it expecting a
>>> CGFloat return and that is handled differently than an integer. So the
>>> call site and the implementation of how your width is done disagree
>>> and you get some strange heisenvalue back.
>>>
>>> When you cast the variable to "Result*", Objective-C now knows to use
>>> YOUR implementation of @selector(width) and it sets up the call site
>>> properly.
>>
>> _______________________________________________
>>
>> 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

_______________________________________________

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: 
 >Strange property/synthesized accessor behaviour (From: Philipp Leusmann <email@hidden>)
 >Re: Strange property/synthesized accessor behaviour (From: "Stephen J. Butler" <email@hidden>)
 >Re: Strange property/synthesized accessor behaviour (From: Philipp Leusmann <email@hidden>)
 >Re: Strange property/synthesized accessor behaviour (From: Anders Norlander <email@hidden>)

  • Prev by Date: Remove KVO for MKAnnotationViews
  • Next by Date: NSManagedObjected isInserted
  • Previous by thread: Re: Strange property/synthesized accessor behaviour
  • Next by thread: Re: Strange property/synthesized accessor behaviour
  • Index(es):
    • Date
    • Thread