ios – 如何按天分组核心数据?

我有一个名为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;
})

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...