Skip to content

Instantly share code, notes, and snippets.

@adamgall
Created May 7, 2014 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamgall/594761878e8a27495980 to your computer and use it in GitHub Desktop.
Save adamgall/594761878e8a27495980 to your computer and use it in GitHub Desktop.
fetchEventDays
- (void)fetchEventDays
{
NSExpression *startDateTimeExpression = [NSExpression expressionForKeyPath:@"startDateTime"];
NSExpression *minStartDateTime = [NSExpression expressionForFunction:@"min:" arguments:[NSArray arrayWithObject:startDateTimeExpression]];
NSExpression *maxStartDateTime = [NSExpression expressionForFunction:@"max:" arguments:[NSArray arrayWithObject:startDateTimeExpression]];
NSExpressionDescription *minStartDateTimeExpression = [[NSExpressionDescription alloc] init];
minStartDateTimeExpression.name = @"minEventStartTime";
minStartDateTimeExpression.expression = minStartDateTime;
minStartDateTimeExpression.expressionResultType = NSDateAttributeType;
NSExpressionDescription *maxStartDateTimeExpression = [[NSExpressionDescription alloc] init];
maxStartDateTimeExpression.name = @"maxEventStartTime";
maxStartDateTimeExpression.expression = maxStartDateTime;
maxStartDateTimeExpression.expressionResultType = NSDateAttributeType;
NSManagedObjectContext *context = [RKObjectManager sharedManager].managedObjectStore.mainQueueManagedObjectContext;
NSEntityDescription* entity = [NSEntityDescription entityForName:@"NIModelScheduleData" inManagedObjectContext:context];
NSAttributeDescription* startDayDesc = [entity.attributesByName objectForKey:@"startDay"];
NSFetchRequest* fetch = [[NSFetchRequest alloc] init];
fetch.entity = entity;
fetch.propertiesToFetch = [NSArray arrayWithObjects:startDayDesc, minStartDateTimeExpression, maxStartDateTimeExpression, nil];
fetch.propertiesToGroupBy = [NSArray arrayWithObject:startDayDesc];
fetch.resultType = NSDictionaryResultType;
NSError *error = nil;
NSArray *results = [context executeFetchRequest:fetch error:&error];
NSLog(@"%@", results);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment