Skip to content

Instantly share code, notes, and snippets.

@ariok
Created December 3, 2013 13:51
Show Gist options
  • Save ariok/7769440 to your computer and use it in GitHub Desktop.
Save ariok/7769440 to your computer and use it in GitHub Desktop.
Fetching data with predicate and sorting
- (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