Skip navigation.
 
mlRe: SetControlReference equivalent in NSControl?
FROM : Kevin Elliott
DATE : Wed Jun 25 22:01:26 2008

On Jun 24, 2008, at 3:45 PM, Graham Cox wrote:

> Bear in mind that the typical purpose of a ControlRef in Carbon is 
> to keep track of an associated wrapper object (or other extended 
> data). In Cocoa, NSControl already is that object. The way to extend 
> an object is to subclass it and add whatever ivars you need. So 
> there would appear to be no need for an equivalent to a ControlRef 
> in the Carbon sense.


There is no reason to subclass his control to attach an int value (or 
more generally to track which instance a particular control is).  See 
NSControl tag/setTag.  They allow you to do exactly what he wants.

Additionally if you want to attach some sort of object (say a string 
or something more complex that needs to be retained) see 
representedObject/setRepresentedObject.  It's part of NSCell not 
NSControl, but most of the complex controls have a NSCell subclass 
anyway (i.e. an NSButtonCell is attached to every NSButton).

> On 25 Jun 2008, at 4:53 am, <email_removed> wrote:
>

>> Hi,
>>
>> In Carbon you can tie a 32 bit value to a control with 
>> SetControlReference.  Is there an equivalent method in NSControl? 
>> I looked around in the header files but couldn't find anything 
>> (NSControl, NSView, NSResponder, NSObject).

Related mailsAuthorDate
mlSetControlReference equivalent in NSControl? jeffs87 Jun 24, 20:53
mlRe: SetControlReference equivalent in NSControl? Kyle Sluder Jun 24, 20:58
mlRe: SetControlReference equivalent in NSControl? Graham Cox Jun 25, 00:45
mlRe: SetControlReference equivalent in NSControl? Kevin Elliott Jun 25, 22:01
mlRe: SetControlReference equivalent in NSControl? Graham Cox Jun 26, 06:39
mltag != pointer under GC (was Re: SetControlReference equivalent in NSControl?) Chris Hanson Jun 26, 07:11