[英]Order returned CoreData entities for NSArray
I am trying to arrange the returned core data entities by the value of a attribute "depart time" currently I have this code, but the order is not changed they are saved to the array in the same order regardless of NSSortDescriptor 我正在尝试通过属性“离开时间”的值来安排返回的核心数据实体,目前我有此代码,但是顺序没有更改,无论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"];
You are not actually doing anything with the SortDescriptor there. 您实际上并没有使用SortDescriptor做任何事情。 In fact you are ignoring it completely.
实际上,您完全忽略了它。
Try this instead... 试试这个...
NSSortDescriptor *timeSD = [NSSortDescriptor sortDescriptorWithKey:@"departtime" ascending:YES];
[request setSortDescriptors:@[timeSD]];
That will add the sort descriptor to the request. 这会将排序描述符添加到请求中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.