Re: Linking a model to an UndoManager with KVC/KVO
Re: Linking a model to an UndoManager with KVC/KVO
- Subject: Re: Linking a model to an UndoManager with KVC/KVO
- From: Ulrich Hobelmann <email@hidden>
- Date: Tue, 05 Dec 2006 22:08:08 +0100
Ulrich Hobelmann wrote:
Since setValue:forKey: takes two parameters, I can't use
registerUndoWithTarget:selector:object:. Instead I did a
[[undoManager prepareWithInvocationTarget:model]
setValue:oldValue forKey:path];
...
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.
For the record (Michael Ash and some others answered this one on Usenet):
The problem wasn't my KVC, but that NSUndoManager uses a proxy object
that only records calls that aren't part of NSObject's interface for the
prepareWithInvocationTarget: method. So setValue:forKey: wasn't
recorded, but instead triggered the above error.
I'd say this is a bug, but Mike said that it was documented somewhere.
Anyway, the workaround is to simply write a new method for the model,
like setUndoValue:forKey: that will call setValue:forKey on self. Then
call *this* method on the undoManager's prepare... proxy object.
(Similar forwarding methods can be used to work around all other methods
of NSObject, if they are wanted in a context with an NSUndoManager.)
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