Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I went through to make a little code (didn't try running it or really go over it so there might be a couple of mistakes, but it has the general idea) to do what you're looking for. Performance wise, it probably won't be the best if you start running into huge amounts of data. I'm sure there's a better way to do this, but I felt like doing it the most basic way as a "temporary fix" answer.</p> <pre><code>NSMutableArray *copiedarray = [YourFirstArray mutableCopy]; NSMutableArray *sortedarray = [[NSMutableArray alloc] init]; NSMutableArray *tempgroup = nil; NSSortDescriptor * groupSorter = [NSSortDescriptor sortDescriptorWithKey:@"time" ascending:YES]; NSInteger i; NSInteger savedlowest = -1; NSString *savedname = @""; while ([copiedarray count] &gt; 0) { ///reset lowest time and group savedlowest = -1; savedname = @""; ///grab the lowest time and group name for (ii = 0;ii &lt; [copiedarray count]; ii++) { if (savedlowest==-1 || ((YourClass *)([copiedarray objectAtIndex:ii])).time&lt;savedlowest)) { savedname = ((YourClass *)([copiedarray objectAtIndex:ii])).name; savedlowest = ((YourClass *)([copiedarray objectAtIndex:ii])).time; } } //we have the lowest time and the type so we grab all those items from the group tempgroup = [[NSMutableArray alloc] init]; for (ii = [copiedarray count]-1;ii &gt; -1; ii--) { if ([((YourClass *)([copiedarray objectAtIndex:ii])).name isEqualToString:savedname]) { ///the item matches the saved group so we'll add it to our temporary array [tempgroup addObject:[copiedarray objectAtIndex:ii]]; ///remove it from the main copied array for "better performance" [copiedarray removeObjectAtIndex:ii]; } } [tempgroup sortUsingDescriptors:[NSArray arrayWithObject:groupSorter]]; [sortedarray addObjectsFromArray:tempgroup]; [tempgroup release]; tempgroup = nil; } </code></pre> <p>In the end you'll end up with what you're looking for in <code>sortedarray</code>.</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. This table or related slice is empty.
    1. 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