我有一个Agency
具有 fetched property 的实体city
。我正在执行 fetch 请求,我希望我的结果按机构name
和城市排序name
。
这是旧代码的一部分。如您所见,与实体存在关系City
,我可以轻松设置排序描述符。但是现在我已经用获取的属性替换了关系。
请帮助我,我需要如何修改此代码?
self.context = //...
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *callEntity = [NSEntityDescription entityForName:@"Agency" inManagedObjectContext:self.context];
[fetchRequest setEntity:callEntity];
NSSortDescriptor *sortByCityNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"city.name" ascending:YES selector:@selector(caseInsensitiveCompare:)];
NSSortDescriptor *sortByNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:)];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortByCityNameDescriptor, sortByNameDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
//performing a fetch