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


_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to