Objective c NSFetchRequest propertiesToGroupBy是否可以不区分大小写?

Objective c NSFetchRequest propertiesToGroupBy是否可以不区分大小写?,objective-c,core-data,grouping,nsfetchrequest,Objective C,Core Data,Grouping,Nsfetchrequest,我有以下用于获取和分组搜索结果的代码: NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Song"]; [request setPredicate:[NSCompoundPredicate andPredicateWithSubpredicates:predicates]]; [request setResultType:NSDictionaryResultType]; [request setSort

我有以下用于获取和分组搜索结果的代码:

NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Song"];
[request setPredicate:[NSCompoundPredicate andPredicateWithSubpredicates:predicates]];
[request setResultType:NSDictionaryResultType];
[request setSortDescriptors: @[[NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:YES]]];

NSExpression *countExpression = [NSExpression expressionWithFormat:@"count:(SELF)"];
NSExpressionDescription *expressionDescriprion = [[NSExpressionDescription alloc] init];
[expressionDescriprion setName:@"count"];
[expressionDescriprion setExpression:countExpression];
[expressionDescriprion setExpressionResultType:NSInteger64AttributeType];

NSArray *properties = @[@"artistName", @"songName"];
[request setPropertiesToFetch:[properties arrayByAddingObject:expressionDescriprion]];
[request setPropertiesToGroupBy:properties];

self.fetchedItems = [self.managedObjectContext executeFetchRequest:request error:nil];
这很好,但是我遇到了一个问题,并且有点结巴,所以我需要使这个propertiesToGroupBy(属性类型是NSString*)不区分大小写。目前,我有以下输出

<_PFArray 0x7fa3e3ed0d90>(
{
    artistName = "System of a Down";
    count = 44;
    songName = "Lonely Day";
},
{
    artistName = "System Of A Down";
    count = 2;
    songName = "Lonely Day";
},
{
    artistName = "System of a Down";
    count = 4;
    songName = "Chop Suey";
}
)
(
{
artistName=“下行系统”;
计数=44;
songName=“孤独日”;
},
{
artistName=“下行系统”;
计数=2;
songName=“孤独日”;
},
{
artistName=“下行系统”;
计数=4;
songName=“杂碎”;
}
)
这是不正确的,所以我需要前两个项目是在单一的部分,因为这是同一个艺术家


有什么方法可以做到这一点吗?

尝试使用NSExpressionDescription:

NSExpression *artistKeyPathExpression = [NSExpression expressionForKeyPath:@"artistName"];
NSExpression *artistExpression = [NSExpression expressionForFunction:@"uppercase:" arguments:@[artistKeyPathExpression]];
NSExpressionDescription *artistExpressionDescription = [NSExpressionDescription new];
artistExpressionDescription.name = @"groupByArtist";
artistExpressionDescription.expression = artistExpression;
artistExpressionDescription.expressionResultType = NSStringAttributeType;

NSExpression *songKeyPathExpression = [NSExpression expressionForKeyPath:@"songName"];
NSExpression *songExpression = [NSExpression expressionForFunction:@"uppercase:" arguments:@[songKeyPathExpression]];
NSExpressionDescription *songExpressionDescription = [NSExpressionDescription new];
songExpressionDescription.name = @"groupBySongName";
songExpressionDescription.expression = songExpression;
songExpressionDescription.expressionResultType = NSStringAttributeType;

[request setPropertiesToGroupBy:@[artistExpressionDescription, songExpressionDescription]];

请注意,我现在无法在XCode中检查此代码,因此它可能包含打印错误。对此很抱歉,但我认为要点很清楚。

对于我来说,按NSExpressionDescription进行分组似乎是不可能的。在[请求setPropertiesToGroupBy:myExpressions]之后;我总是有“NSInvalidArgumentException”,原因是:“无效的键路径表达式。”