• 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: How do I get access to the control within a NSToolbarItem?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I get access to the control within a NSToolbarItem?


  • Subject: Re: How do I get access to the control within a NSToolbarItem?
  • From: Daryle Walker <email@hidden>
  • Date: Sun, 03 Aug 2014 16:12:02 -0400

On Aug 3, 2014, at 3:35 PM, Jens Alfke <email@hidden> wrote:

> On Aug 3, 2014, at 11:56 AM, Daryle Walker <email@hidden> 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@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


  • Follow-Ups:
    • Re: How do I get access to the control within a NSToolbarItem?
      • From: Jens Alfke <email@hidden>
References: 
 >How do I get access to the control within a NSToolbarItem? (From: Daryle Walker <email@hidden>)
 >Re: How do I get access to the control within a NSToolbarItem? (From: Kyle Sluder <email@hidden>)
 >Re: How do I get access to the control within a NSToolbarItem? (From: Daryle Walker <email@hidden>)

  • Prev by Date: Re: How do I get access to the control within a NSToolbarItem?
  • Next by Date: Re: About an alternative menu choice and toolbar buttons.
  • Previous by thread: Re: How do I get access to the control within a NSToolbarItem?
  • Next by thread: Re: How do I get access to the control within a NSToolbarItem?
  • Index(es):
    • Date
    • Thread