2
我正在使用核心数据并基于ID数组获取结果。这个ID数组是我需要获取的序列。但是取得的结果不是这样的顺序。我应该怎么做才能获取完全匹配ID数组顺序的对象?Coredata提取请求与序列顺序
// get manageObjectContext
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"SomeName"
inManagedObjectContext:context];
[fetchRequest setEntity:entity];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"%K IN %@", @"anId", arr];
NSError *error;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
fetchRequest = nil;
其未按升序排列,顺序不同 – sajaz
的.sort({$ 0.property> $ 1.property})如果你想有一个特定的顺序是什么呢? –