Linking a model to an UndoManager with KVC/KVO
Linking a model to an UndoManager with KVC/KVO
- Subject: Linking a model to an UndoManager with KVC/KVO
- From: Ulrich Hobelmann <email@hidden>
- Date: Tue, 05 Dec 2006 12:25:30 +0100
Hi, I'm trying to tack an UndoManager onto my model
(plain-old-OC-object), and of course I'd like to not type everything
myself, so I'm using KVO to observe model changes (by which I get the
model's attribute in the "path" parameter). I'd like to use KVC to have
the undoManager change that same attribute back on undo: (obviously).
Since setValue:forKey: takes two parameters, I can't use
registerUndoWithTarget:selector:object:. Instead I did a
[[undoManager prepareWithInvocationTarget:model]
setValue:oldValue forKey:path];
AFAI can see, my model is KVC-compliant, i.e. it has foo and setFoo:
methods for every attribute 'foo', but that doesn't seem to be enough.
I get the following error message when I trigger a model change (via
Cocoa-bound view objects, in this case a checkbox):
Error setting value for key path selection.foo of object
<NSObjectController: 0x340840>[object class: QSModel] (from bound object
<NSButton: 0x31c7f0>): [<NSUndoManager 0x3484a0>
setValue:forUndefinedKey:]: this class is not key value coding-compliant
for the key foo.
The funny thing is that the click shouldn't even trigger the actual
undo:, it should only *insert* the change into the undoManager (which I
gather from the Apple docs is what you use either the registerUndo... or
the prepareWith... method for). Is there anything else I have to do to
be KVC-compliant?
Thanks,
Ulrich
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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