2014-03-31 66 views
0

我想通過屬性「出發時間」的值來安排返回的核心數據實體,目前我有這個代碼,但順序沒有改變,它們被保存到相同的數組中無論NSSortDescriptor的順序如何爲NSArray訂購返回的CoreData實體

NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Device"]; 

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"thetrip=%@",searchid]; 

[request setEntity:[NSEntityDescription entityForName:@"Device" inManagedObjectContext:managedObjectContext]]; 

[request setPredicate:predicate]; 
self.device = [[managedObjectContext executeFetchRequest:request error:nil] mutableCopy]; 
[NSSortDescriptor sortDescriptorWithKey:@"departtime" ascending:YES]; 
NSLog(@"the predicate is= %@", predicate); 

NSError *error = nil; 

NSArray *results = [managedObjectContext executeFetchRequest:request error:&error]; 

NSArray *areuslter=[self.device valueForKey:@"arriveairport"]; 
NSArray *areusltses=[self.device valueForKey:@"thetrip"]; 

回答

3

您實際上並沒有對SortDescriptor做任何事情。事實上你完全無視它。

試試這個...

NSSortDescriptor *timeSD = [NSSortDescriptor sortDescriptorWithKey:@"departtime" ascending:YES]; 
[request setSortDescriptors:@[timeSD]]; 

這將排序描述符添加到請求。