I have the following code to fetch and group 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 well, but I ran into a problem and the view got stuck, so I need to make this ToGroupBy property (property type NSString *) case-insensitive somehow . At the moment , I have the 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 wrong, so I need the first 2 elements to be in the same section, because this is the same artist.
Is there any way to achieve this?
source share