Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/sortedArrayUsingDescriptors:" rel="noreferrer"><code>sortedArrayUsingDescriptors:</code></a> <code>NSArray</code> method does most of what you need:</p> <blockquote> <p>The first descriptor specifies the primary key path to be used in sorting the receiver’s contents. Any subsequent descriptors are used to further refine sorting of objects with duplicate values. See NSSortDescriptor for additional information.</p> </blockquote> <p>Some filtering with <code>NSPredicate</code> is required too:</p> <pre><code>NSSortDescriptor *timeSD = [NSSortDescriptor sortDescriptorWithKey: @"time" ascending: YES]; NSMutableArray *sortedByTime = [UnsortedArray sortedArrayUsingDescriptors: timeSD]; NSMutableArray *sortedArray = [NSMutableArray arrayWithCapacity:[sortedByTime count]]; while([sortedByTime count]) { id groupLead = [sortedByTime objectAtIndex:0]; NSPredicate *groupPredicate = [NSPredicate predicateWithFormat:@"name = %@", [groupLead name]]; NSArray *group = [sortedByTime filteredArrayUsingPredicate: groupPredicate]; [sortedArray addObjectsFromArray:group]; [sortedByTime removeObjectsInArray:group]; } </code></pre> <p>I have no idea if this is the most efficient method, but until you have reason to believe that it is causing problems there's no need to worry the performance implications. It's premature optimisation. I wouldn't have any concerns about the performance of this method. You've got to trust the framework otherwise you'll end up rewriting it (thus undermine the point of the framework) due to an unfounded paranoia. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload