Re: Fun (or not) with NSArrayControllers and CoreData.
Re: Fun (or not) with NSArrayControllers and CoreData.
- Subject: Re: Fun (or not) with NSArrayControllers and CoreData.
- From: Daniel DeCovnick <email@hidden>
- Date: Wed, 29 Jul 2009 14:30:36 -0700
On Jul 29, 2009, at 12:40 PM, Quincey Morris wrote:
On Jul 29, 2009, at 11:27, Daniel DeCovnick wrote:
I read over the Ensuring KVO compliance docs, and I have to say, I
don't think I understand it. At first glance it looks fine to me,
but obviously it's not. Do I have to implement mutableSet/
ArrayValueForKey: myself, or am I completely on the wrong track?
Your NSManagedObject subclass Job, if I've got the naming right, has
a array property "allDescendentsJobs". The NSArrayController has as
its content array the *root* Job object. Therefore, the
NSArrayController is only going to get a KVO notification if the
"allDescendentsJobs" property of the *root* Job changes KVO-
compliantly.
I'm sorry, you misunderstand. My NSManagedObject subclass Folder, not
Job, has the allDescendantsJobs, and the NSTreeController/
NSOutlineView has all Folders where parent==nil as its root objects.
There is a one Folder to many Jobs relationship. Folders and their
children (and their children, etc.) show up in the outline view, and
there's a table view of Jobs for the selected Folder (and, ideally,
it's children).
So ask: what is going to cause the "allDescendentsJobs" property of
the *root* Job to be updated KVO-compliantly? Answer: nothing,
because the property value is only created on demand (i.e. the first
time the NSArrayController refers to it), and thereafter the
property is read-only.
I'm perfectly happy and able to put a -newJobAndRefetch: method in my
window controller (the xib's File's Owner), but that's insufficient
except for the display problem.
snipped...
I don't think very much of that still applies given the
misunderstanding above.
Finally, one thing that helps with this problem is to give up on
trying to use KVO *on this property* to keep your user interface up-
to-date and write a data source delegate instead.
Hmm... That may be the easier thing to do.
Also (whew!), NSOutlineView + NSTreeController + NSArrayController +
KVO + undo is reputed to have bugs, so you may do everything right
and then have your application crash after the user does an undo.
(I've run into this problem personally, but by the time you get
there the circumstances are so murky it's hard to know who to blame.
But the archives do claim this is a bug, and no one from Apple has
denied it AFAIK.)
Oi vey...
-Daniel
_______________________________________________
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