How to group data by day with kernel data?

I have an Entity called deal , and deal has a date property, which is the time this transaction object is inserted into the repository.

and one day may have several deal s.

So I want to count the amount of data by day, I want to get day and countofsomething
as:

 2013-06-03 3 2013-06-02 4 

and I don't want to use sectionPath because it only sectionPath deals in a section.

I know that I can do this with another property (type: string) like dayOfTheDate , which is similar to 2013-06-03 in each object.

btw, the transient property doesn't seem to work in this situation

Could you please understand what I'm looking for?

Comment here so I can provide more details

Thank you everybody.

+4
source share
1 answer

An example of how I did this when I counted the number of the same notes

 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 will be something like this.

 ({ count = 1; notes = "glenny and me"; }, { count = 6; notes = macair; }) 
+4
source

Source: https://habr.com/ru/post/1484185/


All Articles