我需要从两个不同的实体中执行提取,合并它们,然后根据两个实体都具有的字段对它们进行排序:'lastModifiedDate'。lastModifiedDate 是 NSDate
NSFetchRequest *fetchRequest1 = [[NSFetchRequest alloc] init];
NSFetchRequest *fetchRequest2 = [[NSFetchRequest alloc] init];
NSEntityDescription *entity1 = [NSEntityDescription entityForName:@"Entity1" inManagedObjectContext:self.managedObjectContext];
[fetchRequest1 setEntity:entity1];
NSEntityDescription *entity2 = [NSEntityDescription entityForName:@"Entity2" inManagedObjectContext:self.managedObjectContext];
[fetchRequest2 setEntity:entity2];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastModeifiedDate" ascending:NO];
NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil];
[fetchRequest1 setSortDescriptors:sortDescriptors];
[fetchRequest2 setSortDescriptors:sortDescriptors];
[self.managedObjectContext executeFetchRequest:fetchRequest onSuccess:^(NSArray *results) {
[self.refreshControl endRefreshing];
self.objects = results; //objects is an array @property
[self.tableView reloadData];
} onFailure:^(NSError *error) {
[self.refreshControl endRefreshing];
NSLog(@"An error %@, %@", error, [error userInfo]);
}
我被困在这里。我需要合并 fetchRequest1 和 fetchRequest2,并让对象按降序显示在 tableViewController 中。谢谢。