Skip navigation.
 
mlProgrammatically determine keys in an controller
FROM : Greg Hurrell
DATE : Tue Apr 26 22:44:03 2005

If you select an NSArrayController in Interface Builder you will see 
a listing of "Keys" in the inspector window. For example, if you bind 
the value of an NSTableColumn to the controller with a keypath of 
"arrangedObjects.myKeyPath", then you'll see "myKeyPath" in the 
controller's inspector.

Is there any way to programmatically query an NSArrayController at 
runtime to get that listing of keys?

At the moment the only way I can see to get this information is to 
subclass the NSTableColumn bound to the controller, override the 
bind:toObject:withKeyPath:options: method, and extract the key from 
the key path there. But the controller must also know the key path, 
otherwise it wouldn't appear in the inspector, so I'd like to figure 
out how to ask the controller for the list of keys...

Snooping with class-dump shows this undocumented method in NSController:

- (id)_declaredKeys;

And it does indeed return the same list of keys that the Interface 
Builder inspector shows. It's awfully tempting to use this method 
even though it's not documented, but I am worried about possible 
future code breakage and am hesitant to use it in a shipping app. Any 
comments or ways to achieve the same result without resorting to 
undocumented methods?

Cheers,
Greg

Related mailsAuthorDate
mlProgrammatically determine keys in an controller Greg Hurrell Apr 26, 22:44
mlRe: Programmatically determine keys in an controller Ondra Cada Apr 26, 23:50