Ah, that's clear, but I now see why I'm going wrong.

The object in question is actually a class, where it has a class method +style. 
But the class is passed as the 'object' parameter of a notification, which has 
type id. How do I typecast that to the precise class type I'm expecting? Using 
(MyClass*) doesn't work because that is an instance. It's probably obvious, but 
I'm not stumbling upon it...

--Graham


On 14/10/2011, at 11:28 AM, Jens Alfke wrote:

> 
> On Oct 13, 2011, at 4:29 PM, Graham Cox wrote:
> 
>> When I go into this warning, it further states it's using 
>> [NSProgressIndicator style] instead of my own declared method style which 
>> exists in many different objects (and which would be correct).
> 
> This only happens when calling -style on an untyped (id) pointer. Cast the 
> pointer to your class and you won’t have a problem. Instead of
>       [[array lastObject] style]
> use
>       [(MyClass*)[array lastObject] style]
> This has the added advantage that, if you ever renamed or removed your -style 
> method, the compiler would be able to warn you if you didn’t fix this call.
> 
>> (<RANT> why do Apple have to steal such obvious names when they know there 
>> is a namespace problem? This could easily have been named 
>> 'progressIndicatorStyle' and have much less chance of clashing with user 
>> code.
> 
> I would rather have shorter, clearer names in framework classes. The 
> name-collision thing doesn’t happen to me often, and when it does I just use 
> a typecast like above.
> 
> —Jens

_______________________________________________

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

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

Reply via email to