Re: Another bindings conundrum (editing a to-many relationship through an NSArrayController)
Re: Another bindings conundrum (editing a to-many relationship through an NSArrayController)
- Subject: Re: Another bindings conundrum (editing a to-many relationship through an NSArrayController)
- From: Quincey Morris <email@hidden>
- Date: Thu, 17 Mar 2011 22:25:07 -0700
On Mar 17, 2011, at 11:01, Luke Evans wrote:
> The column for Territories in the master SalesRep table is bound so that
> cell values should be the relationship set.
I'm not sure I can nail the problem down exactly, since your setup is fairly complex, but I'm pretty sure the above is the cause of the problem. There *isn't* any such thing as the relationship set, not really.
If you request [salesRep valueForKey: @"Territories"] -- the property really ought to be a lower-case "territories", BTW -- you'll get a set, but it's just a set. Nothing promises that the set represents the relationship. It's just a set of the things in the relationship, and could be a transient object created only in response to your request for the related territories. Since it's showing up as a _NSFaultingMutableSet, it's probably some kind of set proxy whose internal implementation fetches actual objects lazily from the Core Data store.
Something like this:
[[salesRep valueForKey: @"Territories"] addObject: someObject]
doesn't mutate the relationship. For that, you need to use a mutable set proxy:
[[salesRep mutableSetValueForKey: @"Territories"] addObject: someObject]
That's what array controllers normally to do change relationships, I believe. In your case, you've defeated this by using your so-called relationship set directly. In other words, you've just connected your array controller to a contentSet; you haven't actually bound anything that matters to the "Territories" property of the salesRep object.
At least, I think that's what's wrong. To fix it, I think you need to do either of two equivalent things:
a. pass the salesRep object and the name of the property "Territories" through to the cell, rather than passing the transient set through, and access the property via KVC, further downstream
b. pass a mutable set proxy for the relationship through to the cell, and connect the array controller to that
Sorry if that all sounds a bit vague.
_______________________________________________
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