我有一个名为deal的实体,交易有一个名为date的属性,这是此交易对象插入商店的时间.
有一天可能有几笔交易.
所以我想要按天计算一些数据组,我想要获取日期和数量的东西
喜欢:
2013-06-03 3 2013-06-02 4
我不想使用sectionPath,因为它只将交易放入section.
我知道我可以通过另一个属性(类型:字符串)来实现这一点,例如dayOfTheDate,就像每个对象中的2013-06-03.
你能理解我在找什么吗?
谢谢大家.
解决方法
当我计算相同音符的数量时,我是如何做到的样本
NSEntityDescription* entity = [NSEntityDescription entityForName:@"Assets" inManagedobjectContext:[appDelegate managedobjectContext]]; NSAttributeDescription* statusDesc = [entity.attributesByName objectForKey:@"notes"]; NSExpression *keyPathExpression = [NSExpression expressionForKeyPath: @"assetUrl"]; // Does not really matter NSExpression *countExpression = [NSExpression expressionForFunction: @"count:" arguments: [NSArray arrayWithObject:keyPathExpression]]; NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init]; [expressionDescription setName: @"count"]; [expressionDescription setExpression: countExpression]; [expressionDescription setExpressionResultType: NSInteger32AttributeType]; [searchFetchRequest setPropertiesToFetch:[NSArray arrayWithObjects:statusDesc,expressionDescription,nil]]; [searchFetchRequest setPropertiesToGroupBy:[NSArray arrayWithObject:statusDesc]]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timestamp" ascending:NO]; [searchFetchRequest setSortDescriptors:@[sortDescriptor]]; [searchFetchRequest setFetchLimit:10]; nspredicate *query = [nspredicate predicateWithFormat:@"notes contains[cd] %@",_txtCameraNote.text]; [searchFetchRequest setPredicate:query]; [searchFetchRequest setResultType:NSDictionaryResultType]; NSArray *fetchedobjects = [appContext executeFetchRequest:searchFetchRequest error:nil];
fetchedobjects就是这样的.
({ count = 1; notes = "glenny and me"; },{ count = 6; notes = macair; })