Created
December 3, 2013 13:51
-
-
Save ariok/7769440 to your computer and use it in GitHub Desktop.
Fetching data with predicate and sorting
This file contains hidden or 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
- (Entry*)entryForDate:(NSDate *)date inContext:(NSManagedObjectContext*)context{ | |
NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"Entry"]; | |
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"since >= %@",date]; | |
request.predicate = predicate; | |
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"since" ascending:YES]; | |
request.sortDescriptors = @[sort]; | |
NSArray *results = [context executeFetchRequest:request error:nil]; | |
Entry *entry; | |
if([results count] > 0){ | |
entry = [results objectAtIndex:0]; | |
} | |
return budget; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment