Created
May 9, 2014 10:30
-
-
Save hachinobu/998b8ae26065b8e069c2 to your computer and use it in GitHub Desktop.
CoreDataでcount関数を使う
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//集計対象 | |
NSExpression *keyPathExpression = [NSExpression expressionForKeyPath:@"column1"]; | |
//集計関数countを指定 | |
NSExpression *countExpression = [NSExpression expressionForFunction:@"count:" arguments:@[keyPathExpression]]; | |
//集計式の対象(NSExpressionDescription ) | |
NSExpressionDescription *expressionDescription = [[[NSExpressionDescription alloc] init] autorelease]; | |
[expressionDescription setName:@"count"]; | |
[expressionDescription setExpression:countExpression]; | |
[expressionDescription setExpressionResultType:NSInteger32AttributeType]; | |
[fetchRequest setPropertiesToGroupBy:@[column2]]; | |
[fetchRequest setPropertiesToFetch:@[column2, expressionDescription]]; | |
[fetchRequest setResultType:NSDictionaryResultType]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment