• 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: NSArrayControllers and sorting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArrayControllers and sorting


  • Subject: Re: NSArrayControllers and sorting
  • From: Jim Hamilton <email@hidden>
  • Date: Sat, 6 Aug 2005 17:05:22 -0400


On Aug 6, 2005, at 3:25 PM, Edwin Vane wrote:

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).

Ah, so you're worried about performance... -setSortDescriptors: followed by -arrangeObjects: will be "correct", but not necessarily fast enough.


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?

You still don't need to subclass... Instead, write a category method on NSMutableArray that finds the right place to insert the new object, and call -insertObject:atIndex:. Better?


Jim H
--
Jim Hamilton

email@hidden
email@hidden

_______________________________________________
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


References: 
 >NSArrayControllers and sorting (From: Edwin Vane <email@hidden>)
 >Re: NSArrayControllers and sorting (From: Jim Hamilton <email@hidden>)

  • Prev by Date: Re: Save authentication to keychain
  • Next by Date: NXSetMouseScaling replacement
  • Previous by thread: Re: NSArrayControllers and sorting
  • Next by thread: Re: NSArrayControllers and sorting
  • Index(es):
    • Date
    • Thread