• 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: forwarding KVO from NSDocument to model
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: forwarding KVO from NSDocument to model


  • Subject: Re: forwarding KVO from NSDocument to model
  • From: Scott Anguish <email@hidden>
  • Date: Thu, 12 May 2005 01:50:48 -0400


On May 11, 2005, at 11:48 AM, Cameron Hayne wrote:


On 11-May-05, at 7:15 AM, Scott Anguish wrote:


if the NSDocument is KVC compliant for those keys, and you're setting them using a KVC compliant means, the NSDocument should work just the same as the existing model object.

On May 11, 2005, at 4:36 AM, Cameron Hayne wrote:


However, it is far from obvious how I should go about setting up the "forwarding" of KVO so that the model changes will get observed. I don't want to have to add an observer for each and every model attribute - but I don't see a nice way to handle it otherwise.




As I said in my original post, the NSDocument doe not have any accessors or instance variables corresponding to the model's instance variables - but it implements valueForUndefinedKey and setValue:forUndefinedKey to forward *all* KVC requests to the model. And this works well - changes in the view do cause changes in the model.



You'd have to implement manual key-value observing in the setValue:forUndefinedKey: method.


What I was asking about is the other direction - if the model changes, how do I arrange that KVO makes the view change in response? Note again that the model is not bound to the view objects - it is the NSDocument (that has a reference to the model) that is bound to the view objects. And I think there should be a *general* way to have the KVO notifications take effect - without having to do it for each individual model attribute separately.

I have not seen this situation mentioned in any documentation or example.

Probably because it's not exactly the best way to do it.

I find this surprising as I would have thought that it was a common situation to have a document-based app where the model is not in the NIB and hence it is necessary to do some "forwarding" of KVO.

no, in this case, you're likely better off to instead create the bindings between the model and the nib when you load the nib.


    it might work, but it isn't the way I'd recommend doing it.

--
"William Cheeseman ... is said not to be a doofus in real life." - Roger Ebert, Chicago Sun-Times Online


Scott Anguish
email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >forwarding KVO from NSDocument to model (From: Cameron Hayne <email@hidden>)
 >Re: forwarding KVO from NSDocument to model (From: Scott Anguish <email@hidden>)
 >Re: forwarding KVO from NSDocument to model (From: Cameron Hayne <email@hidden>)

  • Prev by Date: Re: Add metadata to my files for Spotlight
  • Next by Date: Re: Core Data and NSFetchRequest
  • Previous by thread: Re: forwarding KVO from NSDocument to model
  • Next by thread: Storing file pathes... what to do if the user move/change them ?
  • Index(es):
    • Date
    • Thread