Re: Core Data + NSOutlineView + Sorting without NSTreeController
Re: Core Data + NSOutlineView + Sorting without NSTreeController
- Subject: Re: Core Data + NSOutlineView + Sorting without NSTreeController
- From: "Marcus S. Zarra" <email@hidden>
- Date: Sun, 8 Jul 2007 12:57:33 -0600
If you are going to do that then I would extend the NSManagedObjects
and add the tree functionality to them. This would avoid the need to
keep a parallel set of objects. Then your parents/branches could have
a method that returns the sorted array of children.
Marcus S. Zarra
Zarra Studios LLC
Simply Elegant Software for OS X
www.zarrastudios.com
On Jul 8, 2007, at 12:32 PM, Seth Willits wrote:
Conor,
This suggestion doesn't solve anything (efficiently, anyway). I
don't need to store the sort order, so adding a position attribute
to the model is unnecessary, and second, having to search through
all objects in the set or create a sorted array of the objects each
time to get the one at the correct position is exactly the problem
I'm trying to avoid.
The best solution I've come up with is a non-persistent parallel
tree structure where each node wraps a real object from the tree,
and sort this parallel structure, keeping all operations completely
separate from the persistent objects. I'm hoping KVO will work
nicely enough to observe changes to the children to know when they
must be resorted, a new node added etc, but I just haven't played
with it enough to know for sure.
--
Seth Willits
On Jul 8, 2007, at 7:50 AM, Conor wrote:
Hi Seth,
I would add a NSNumber position attribute to your objects and use
that to
sort. You would have to change the numbers for all objects higher
than where
you insert a new object, but it's no different than having to
recreate your
array. I suggest this solution not because I know but because it's
what I
would do rather keep a separate sorted array for each set of
children.
Regards,
Conor
http://www.bruji.com/
(I couldn't come up with a decent short-and-easy-to-understand
subject for this email that was really accurate, but hopefully
that'll do.)
I've ditched using NSTreeController for a few reasons, so I'm back
to
using the data source methods to display my objects from Core Data.
The question I have is about how best to keep an array of arranged
objects (according to a sort descriptor). Before Core Data I had a
mutable array for my children, so they were always implicitly
ordered, and whenever the sort descriptor changed, I would just
resort the array. (They only every showed up in one place, so there
was never an instance of them needing to be simultaneously sorted in
different ways.)
But how should I do this with Core Data? Given that to-many
relationships are sets, I'm wondering if I should do a similar thing
and keep a sorted array as an instance variable in my
NSManagedObject
subclass and recreate and resort the array every time the objects on
the many side of the relationship change. It would _work_ but it
just
seems so inefficient.
Do any of you have a clever solution as to where should I store the
sorted array and when I should sort it?
_______________________________________________
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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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