我正在尝试按属性的值排列返回的核心数据实体"离开时间"目前我有这个代码,但顺序没有改变,无论NSSortDescriptor是什么,它们都以相同的顺序保存到数组中
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"];
答案 0 :(得分:3)
您实际上并没有使用SortDescriptor做任何事情。事实上,你完全无视它。
试试这个......
NSSortDescriptor *timeSD = [NSSortDescriptor sortDescriptorWithKey:@"departtime" ascending:YES];
[request setSortDescriptors:@[timeSD]];
这会将排序描述符添加到请求中。