On 17 Dec, 2012, at 7:20 PM, Andreas Grosam <agro...@onlinehome.de> wrote:

> 
> On 17.12.2012, at 11:25, Andreas Grosam wrote:
> 
>> I would like to use the property access syntax for a (readonly) property 
>> which is defined in a category and sent to an object whose compile type info 
>> is just "id". Use case:
>> 
>> id obj = …;
>> if (obj.isFoo) {   // <== error: property 'isFoo' not found for object of 
>> type '__strong id'.
>>   ...
>> }
>> 
>> 
>> So, why does message send syntax compiles fine - but property syntax not??
> 
> Well, after thinking a while about the issue, I can answer this myself:
> 
> The compiler requires the type information in order to figure the actual 
> getter signature. When declaring the a property, the getter and setter may be 
> explicitly specified, for example:
> 
> @property (readonly, getter=getFooStateOrWhatever) isFoo;
> 
> Thus, the compiler cannot deduce the setter and getter methods from the 
> property name unless it knows the type. So, in the case above where the type 
> is not known at compile time, I cannot use dot syntax but needs to use method 
> send syntax with the actual getter signature.
> 
> Andreas
> 

Don't see that at all, sorry. The dot syntax a.foo is just another way of 
saying [ a foo ], they are equivalent. The compiler has no more information one 
way or another, it doesn't need to deduce the setter and getter methods, it 
just needs to call the method you've asked it to call, whether the object will 
end up responding to it or not. 

I think the answer is much more to do with being modern. Dot syntax is 
relatively new, and somewhat mirrors the . syntax for structs. They have no 
choice but to allow [ obj selector ] with a random id and selector to be 
acceptable syntax, too much old code using it and you do need a way to say 
'just send it please'. But there was no particular reason to carry that over 
into the dot syntax world and so they didn't and require that an object you ask 
for a property on, or set a property on, is typed. 
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to