Question about KVO

Nibbie
Posts: 2
Joined: 2011.07
Post: #1
Hey guys, first time poster

Just wondering - I'm trying to write a pixeling program and learning quite a lot from the Apple Sketch demo code as I go. It has a comment in SKTWindowController.h that says this:

Code:
This class is KVC and KVO compliant for this key:

"graphicsController" (an NSArrayController; read-only) - The controller that manages the selection for the graphic view in the controlled window.

But I can't find a pair of graphicsController/setGraphicsController functions, or a synthesize declaration, or even an @property or an override of willChangeValueForKey.. nothing.

How is this possible? I don't get how you can be KVC and KVO compliant without any of this. Huh

Thanks!
Quote this message in a reply
⌘-R in Chief
Posts: 1,256
Joined: 2002.05
Post: #2
"If no accessor is found, and the receiver’s class method accessInstanceVariablesDirectly returns YES, the receiver is searched for an instance variable whose name matches the pattern _<key>, _is<Key>, <key>, or is<Key>, in that order."


"+ (BOOL)accessInstanceVariablesDirectly
Return Value
YES if the key-value coding methods should access the corresponding instance variable directly on finding no accessor method for a property, otherwise NO.

Discussion
The default returns YES."



So there you go. But that's a bad practice IMO. If you're publicly exposing it you should be using public setter/getters so that it's obviously bindable.



http://developer.apple.com/library/mac/#...ation.html
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2011.07
Post: #3
Ahh thank you. Man that's sneaky!
Quote this message in a reply
Post Reply