Re: Get|SetControlProperty() equivalent
Re: Get|SetControlProperty() equivalent
- Subject: Re: Get|SetControlProperty() equivalent
- From: Graham Cox <email@hidden>
- Date: Thu, 11 Jun 2009 21:50:56 +1000
On 11/06/2009, at 8:41 PM, Jo Meder wrote:
I'm pretty sure I know the answer to this question, but I'll ask it
anyway :-)...
Is there a Cocoa equivalent to Carbon's Get|SetControlProperty()
family of functions? For those not familiar these functions let you
associate user data with controls. I've never really used this for
much, but it is very useful for storing a pointer to a C++ object
representing the control in a UI framework, for example.
It would be great to be able to do this for NSViews but I haven't
been able to find any equivalent. Are there any ingenious ways that
you might be aware of so I could bolt this on to NSView?
I'm trying to avoid setting up a map from NSViews to UI framework
objects, but I suspect it will be inevitable. Not really a big deal,
but less hassle to be able to associate the data directly so that
would be a preferable solution.
The carbon mechanism exists because in classical procedural code, you
can't subclass an "object" because there is no formal "object" to
subclass. Therefore storage mechanisms have to be provided to hang
extra stuff on.
In Cocoa, we have proper objects, so you can simply (ingeniously!)
subclass the NSControl or NSView as you wish and add any extra data
members you want for any purpose you wish. For example you could
subclass NSView and add a reference to your C++ object directly as a
data member along with suitable accessors for it. If the view needs to
be aware of the C++ code itself you can compile it as Objective-C++
using a .mm extension on the source file.
--Graham
_______________________________________________
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