First, create a Core Data Entity that has: userSearchTerm and userSearchDate. And create a record everytime a search is done.
Start the code by declaring the fetch request.
And use NSPredicate
to filter by date:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"UserSearches" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSPredicate *nameFilter = [NSPredicate predicateWithFormat:@"(userSearchDate like[cd] %@) AND (userSearchTerm like[cd] %@)",weekName,termToFind];
[fetchRequest setPredicate:nameFilter];
The [cd] in the like filter specifies it's not case-sensitive. You may also need to change this filter depending on the date and format you want to use
Then, set the fetchResultType as NSDictionaryResultType
:
[fetchRequest setResultType:NSDictionaryResultType];
This will return a dictionary which you can use.
To use aggregate functions you need to use NSExpressionDescription
This is an extensive code and I'm not able to test it correctly for you, but you can read it here. On section Fetching Specific Values, it describes how to do the aggregate functions:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdFetching.html
For a reference of all the available aggregate functions for NSExpression
go to function expressionForFunction:arguments: where the list is located.