我正在使用通过NSSortDescriptor排序的 NSFetchRequest 。
这对于要获取的实体的所有属性都非常有效。
在该实体中只有一个问题(不是总是存在吗?)我与另一个实体有关系,我也想对这个问题进行排序。但它给了我以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'to-many key not allowed here'
这是我的核心数据设置:
这是我的代码:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entityMonth = [NSEntityDescription entityForName:@"Month" inManagedObjectContext:_managedObjectContext];
[fetchRequest setEntity:entityMonth];
NSSortDescriptor *sortDescriptorItem = [NSSortDescriptor sortDescriptorWithKey:@"item.nr" ascending:YES]; //THIS ONE CAUSES THE ERROR!
NSSortDescriptor *sortDescriptorMonth = [[NSSortDescriptor alloc]initWithKey:@"month" ascending:YES];
NSSortDescriptor *sortDescriptorYear = [[NSSortDescriptor alloc]initWithKey:@"year" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptorYear, sortDescriptorMonth, sortDescriptorItem, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSError *error = nil;
self.stages = [_managedObjectContext executeFetchRequest:fetchRequest error:&error];