• 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: Trouble binding against transient Core Data property
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble binding against transient Core Data property


  • Subject: Re: Trouble binding against transient Core Data property
  • From: Quincey Morris <email@hidden>
  • Date: Mon, 11 Oct 2010 15:26:29 -0700

On Oct 11, 2010, at 14:41, Rick Mann wrote:

> 	[view bind: @"frame" toObject: controller withKeyPath: @"representedObject.frame" options: nil];
>
> And, nope. Now the value in the model puts the view in the specified place, but changing the view's frame does not propagate the change to the model. Does that mean that -[NSView frame] is not KVC-compliant, or that I still need custom code somewhere to create the binding?

Actually, what you did, more or less, was to demonstrate the uni-directional nature of the -[NSObject bind...] when used in isolation. In your original code, half of it worked. In this code, the other half works. :)

> Since each plug-in must subclass NSViewController in order to provide a view to display, I can provide a custom NSViewController subclass for them to use, and put whatever code is necessary into that. But it's not clear to me exactly what I would do, then.

How about something like this:

Give your view controller two properties: "modelFrame" and "viewFrame". Use KVO to derive these properties from the 2 "frame" properties. (You should be able to use 'keyPathsForValuesAffecting<Key>' based on a key path, or you can even use the 'bind...' method if you wish, or you can do it manually via 'addObserver:...'.

Write custom setters for the view controller properties that transfer the frame rect between the view and the model as necessary. You'll have to deal with one level of possible recursion (the setter for one property will probably trigger the other), but you shouldn't have to worry about infinite recursion, because KVO prevents it in a case like this.

That should be all you need to do.

Note: Keary just pointed out in a separate response that you shouldn't rely on NSView's "frame" property being KVO compliant (though I think it is). As he suggests, you can observe the NSView frame-changed notification instead, which is just as easy as a KVO notification.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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: 
 >Trouble binding against transient Core Data property (From: Rick Mann <email@hidden>)
 >Re: Trouble binding against transient Core Data property (From: Quincey Morris <email@hidden>)
 >Re: Trouble binding against transient Core Data property (From: Rick Mann <email@hidden>)
 >Re: Trouble binding against transient Core Data property (From: Quincey Morris <email@hidden>)
 >Re: Trouble binding against transient Core Data property (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: Trouble binding against transient Core Data property
  • Next by Date: Re: Return key should enter return in textfield and not press default button
  • Previous by thread: Re: Trouble binding against transient Core Data property
  • Next by thread: Re: Trouble binding against transient Core Data property
  • Index(es):
    • Date
    • Thread