Created
May 7, 2014 17:53
-
-
Save adamgall/594761878e8a27495980 to your computer and use it in GitHub Desktop.
fetchEventDays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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