• 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 + NSOutlineView + Sorting without NSTreeController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data + NSOutlineView + Sorting without NSTreeController


  • Subject: Re: Core Data + NSOutlineView + Sorting without NSTreeController
  • From: Seth Willits <email@hidden>
  • Date: Sun, 8 Jul 2007 11:32:26 -0700

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


  • Follow-Ups:
    • Re: Core Data + NSOutlineView + Sorting without NSTreeController
      • From: "Marcus S. Zarra" <email@hidden>
References: 
 >Re: Core Data + NSOutlineView + Sorting without NSTreeController (From: Conor <email@hidden>)

  • Prev by Date: Re: [coredata] populate NSPopupButton with NSAttributedStrings
  • Next by Date: Re: UTF-8 string encoding bug in stringWithContentsOfURL?
  • Previous by thread: Re: Core Data + NSOutlineView + Sorting without NSTreeController
  • Next by thread: Re: Core Data + NSOutlineView + Sorting without NSTreeController
  • Index(es):
    • Date
    • Thread