Re: NSArrayControllers and sorting
Re: NSArrayControllers and sorting
- Subject: Re: NSArrayControllers and sorting
- From: Edwin Vane <email@hidden>
- Date: Sat, 6 Aug 2005 15:40:48 -0400
- Mail-followup-to: Cocoa-Dev <email@hidden>
From: Edwin Vane <email@hidden>
To: Jim Hamilton <email@hidden>
Subject: Re: NSArrayControllers and sorting
Reply-To: Edwin Vane <email@hidden>
Hi,
The sort descriptors (unless I'm missing something) are used to sort an
NSMutableArray (via sortUsingSelector:). I have an array that is already
sorted and I want new objects
to be inserted in the correct order. Insertion is linear time but adding
to the end of an array and then sorting the whole array again is worse
(and a waste of time in this case).
>From reading the docs, it would seem that overriding addObject or
insertObject in an array controller subclass to do an ordered insert
would do the trick? Is there a better or more desired approach? I
suppose since it's important that the model is a sorted list, the model
could be subclass of NSMutableArray with add/insert overridden. Perhaps this is
better?
Edwin V
On Sat, Aug 06, 2005 at 10:48:47AM -0400, Jim Hamilton wrote:
>
> On Aug 6, 2005, at 12:47 AM, Edwin Vane wrote:
>
> >Hi,
> >
> >
> >>From the literature I've seen, it looks like array controllers
> >>manage
> >>
> >arrays that have no underlying sorting and that array controllers can
> >present the array in some sorted manner to the view.
> >
> >Now, does it make sense to have a subclass of an array controller (I
> >would guess) to keep the array it's bound to in some permanent sorted
> >order (such as if the array is sorted by floating point time values)?
> >Inserting something into the middle of an array, causing all later
> >elements to be shifted, would trigger a whole bunch of change
> >notifications would it not?
>
> You don't need a subclass. Look at NSSortDescriptors.
>
> <http://developer.apple.com/documentation/Cocoa/Conceptual/
> SortDescriptors/index.html>
>
>
> --
> Jim Hamilton
>
> email@hidden
> email@hidden
>
--
Edwin Vane
MMath Candidate
Computer Graphics Lab
School of Computer Science
University of Waterloo
_______________________________________________
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