I have following code for fetching and grouping search results:
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];
which works very nice but I faced to issue and kind of stucked with, so I need to make this propertiesToGroupBy (property type is NSString *) case insensitive somehow. At the moment I have following output:
<_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";
}
)
which is incorrect, so I need first 2 items to be in single section, cause this is the same artist.
Is there any way to achieve that?