【发布时间】:2016-05-17 18:23:51
【问题描述】:
我正在尝试以最基本的形式使用 group-by 核心数据功能:
- (NSFetchedResultsController *)fetchedResultsController {
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSExpression *reviewNumKeyExpression = [NSExpression expressionForKeyPath:@"review_num"];
NSExpression *reviewMaxExpression = [NSExpression expressionForFunction:@"max:" arguments:[NSArray arrayWithObject:reviewNumKeyExpression]];
NSExpressionDescription *maxReviewED = [[NSExpressionDescription alloc] init];
[maxReviewED setName:@"maxReview"];
[maxReviewED setExpression:reviewMaxExpression];
[maxReviewED setExpressionResultType:NSInteger32AttributeType];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Group" inManagedObjectContext:managedObjectContext];
[fetchRequest setResultType:NSDictionaryResultType];
[fetchRequest setReturnsDistinctResults:YES];
[fetchRequest setEntity:entity];
NSAttributeDescription *groupId = [entity.propertiesByName objectForKey:@"group_id"];
NSArray *propertiesToFetch = [NSArray arrayWithObjects:groupId, maxReviewED, nil];
[fetchRequest setPropertiesToFetch:propertiesToFetch];
[fetchRequest setPropertiesToGroupBy:propertiesToFetch];
...
运行此代码时,我收到以下错误:
由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'无效的键路径表达式 ((), 名称 maxReview, isOptional 1, isTransient 0, entity (null), renamingIdentifier maxDepartment、验证谓词 ()、警告 ()、 versionHashModifier (null) userInfo { }) 传递给 setPropertiesToFetch
我想我在 API 上遗漏了一些东西,所以非常感谢任何帮助!
【问题讨论】: