• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Linking a model to an UndoManager with KVC/KVO
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Linking a model to an UndoManager with KVC/KVO (From: Ulrich Hobelmann <email@hidden>)

  • Prev by Date: Re: 10.4 date format help
  • Next by Date: Re: 10.4 date format help
  • Previous by thread: Linking a model to an UndoManager with KVC/KVO
  • Next by thread: Sub classing.
  • Index(es):
    • Date
    • Thread