cocoa - Help sorting an NSArray across two properties (with NSSortDescriptor?) -


I'm a bit of a NSSortDescriptor n00b, I think, though, what I should do, this is the right tool:

I have NSARR which contains objects with keys, say "name" and "time". Instead of talking about it, here's an example:

  Input: Name: Time B: 4C: 8B: 5C: 4A: 3C: 2A: 1A : 7B: 6 Desired output: Name: Time A: 1 & lt; --- A: 3A: 7C: 2 & lt; --- C: 4C: 8b: 4 & lt; --- B: 5b: 6  

So the values ​​are sorted by "time" and are grouped by "name" first comes first because its shortest time value , And all prices for A come after each other. Then comes, he had the second smallest value of all his values. I have indicated the values ​​that determine how the names have been resolved; Each name occurs within the group, sorting time.

How do I get the most efficient way to get NSA output from input? (CPU- and memory-wise, code is not required.) How do I build nssort descriptors for this, or use any other method? Unless this is the most effective way, I do not want to do my own role.

NSArray The method you need is most important:

The first descriptor specifies the primary key path for sorting the receiver's contents, any subsequent explanation is used to sort objects with duplicate values. See NSSortDescriptor for additional information. Some filtering is also required with

NSPredicate :

  NSSortDescriptor * timeSD = [NSSortDescriptor sortDescriptorWithKey: @ "time" ascending : Yes]; NSMutableArray * Sorted Time = [Unassigned Array Sorting Using Desktops: TimeSide]; NSMutableArray * SortedArray = [NSMutableArray arrayWithCapacity: [sortedByTime count]]; While ([Sorted time calculation]) {id groupLead = [sorted byte time objectindex: 0]; NSPredicate * groupPredicate = [NSPredicate predicateWithFormat: @ "name =% @", [group title]] ;; NSArray * Group = [Sorted Time FilterAruusingProx: Group Advanced]; [Sortedray add objectframe: group]; [Extracted bytime timeBizjectInternet: group]; }  

I do not know that this is the most effective way, but unless you have a reason to believe that it is causing problems, to worry about performance related effects There is no need for that. It is premature adaptation. I will not have any worries about the performance of this method. You have to rely on the framework otherwise you will have to rewrite it (thus weakening the point of the structure) because the reason for a unflinching paranoia


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -