2014-09-12 100 views
0

我想通過其被存儲在對象:)NSSortDescriptor以與陣列中的對象

爲了更好地概覽我已經包括陣列一個陣列內的值進行排序一個NSMutableArray。我想按時間排序(starttijd)

隨着NSSortDescriptor我設法按狀態的url排序,但不是按時間排序。

這是我整理當前的代碼:

NSSortDescriptor * sortDescriptor;sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@「starttuhd」 遞增:YES]; NSArray * sortDescriptors = [NSArray arrayWithObject:sortDescriptor];

sortedarray = [alleitems sortedArrayUsingDescriptors:sortDescriptors]; 
    NSLog(@"Sorted array: %@", sortedarray); 

The array

+1

如果一個對象在具有不同'starttijd'日期的'custom_fields'內有多個對象,該怎麼辦?應該選擇什麼來進行排序? – bhargavg 2014-09-12 10:37:44

+0

什麼是您的實際代碼排序? – Larme 2014-09-12 10:43:51

+0

總是隻有1個starttijd – 2014-09-12 10:44:27

回答

0

首先,如果有永遠只能1 starttijd數組中,那麼爲什麼一個數組?

無論如何,你可以試試這個:

NSSortDescriptor *sortDescriptor; 
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"@max.starttuhd" ascending:YES]; 
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; 
sortedarray = [alleitems sortedArrayUsingDescriptors:sortDescriptors]; 
NSLog(@"Sorted array: %@", sortedarray); 

基本上,@max是KVC收集運營商之一。由於它解析爲數組中的單個元素,因此可能會起作用。