• 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: Core Data, Bindings, and default relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data, Bindings, and default relationships


  • Subject: Re: Core Data, Bindings, and default relationships
  • From: Christopher Frederick <email@hidden>
  • Date: Tue, 21 Jun 2005 06:13:25 -0700


On 平成 17/06/20, at 23:27, Chris Hanson wrote:

There is. Use two NSArrayControllers, one for Items (ItemsController) and one for Purchases (PurchasesController). Make sure their managedObjectContext bindings are set to the same context.

Bind ItemsController's contentSet to PurchasesController's selection.items. This means that instead of handling all Items, ItemsController handles the Items in the "items" relationship of the currently-selected Purchase. So adding an Item via ItemsController will actually add it to that relationship.

Finally, make sure that the Purchase.items relationship and the Item.purchase relationship are inverses. This means that Core Data will automatically maintain both sides of the relationship whenever you modify one side of it. For example, it will automatically set Item.purchase for an Item if you add it to a Purchase's Purchase.items relationship. Even via an array controller.

That worked perfectly.

There were two things I think you were missing: First, that you could bind the contentSet of your Items array controller to a relationship in Purchases, and second, that if you set relationships as inverses of each other that Core Data will automatically maintain either side when the other side changes.

Yes, I did look over NSArrayController's other bindings, but was not sure what to make of contentSet, which is described rather vaguely in the Developer Documentation as "an NSSet that specifies the content of the NSArrayController". Concerning mutual relationships, I had set up the Item and Purchase entity relationships to be inverse from the start and was aware that Core Data maintains their integrity automatically; it was the connection between the two array controllers that never occurred to me. _______________________________________________
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: 
 >Core Data, Bindings, and default relationships (From: Christopher Frederick <email@hidden>)
 >Re: Core Data, Bindings, and default relationships (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: NSOutlineView not always showing "expand triangle"
  • Next by Date: Re: [solved] Another NSXMLParser question (multiple delegates)
  • Previous by thread: Re: Core Data, Bindings, and default relationships
  • Next by thread: How to hook up controllers to a hand generated OM?
  • Index(es):
    • Date
    • Thread