On Aug 3, 2014, at 3:35 PM, Jens Alfke <[email protected]> wrote:

> On Aug 3, 2014, at 11:56 AM, Daryle Walker <[email protected]> wrote:
>> 
>> I just noticed that myself.  Is “(NSSegmentedControl 
>> *)self.toolbarBackForward.view”, a cast to a (2 layers down) subclass, the 
>> way you’re supposed to access the control’s stuff?  It looks like a hack, 
>> but I’ll take it since it (seemingly) works.
> 
> Sure. Why is casting to a subclass a hack? It’s a fact of life in a 
> statically-typed language. (You’re implicitly casting to subclasses all the 
> time, like whenever you access objects in a collection; it’s just that the 
> ‘id’ type saves you the trouble of explicitly having to write the cast. If 
> anything, in this case it’s actually a safer cast since you know the object 
> is a view, whereas with id it could be anything at all.)

It’s my understanding of Objective-C.  I thought you could do:

        [self.toolbarBackForward.view methodOfNSSegmentedControl:blah-blah-blah]

without complaint.  I know that NSView doesn’t have that method, but the actual 
object taking this at runtime is a subclass that does have the desired method.  
I thought the compiler will ignore that fact with a warning instead of an 
error.  Is this something reserved only when using “id” as the static-time 
pointer type?  Am I misremembering seeing Objective-C code that lets this sort 
of stuff through at compile-time because of saving it for run-time?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

_______________________________________________

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