Skip to content

Instantly share code, notes, and snippets.

@jackhl
Created April 10, 2012 20:08
Show Gist options
  • Save jackhl/2354122 to your computer and use it in GitHub Desktop.
Save jackhl/2354122 to your computer and use it in GitHub Desktop.
core data fetch
NSString *currentChromosome = @"18";
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Gene"];
NSSortDescriptor *alphaSortNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"acronym" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:alphaSortNameDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"chromosome.identity = %@", currentChromosome];
[fetchRequest setPredicate:predicate];
NSError *fetchError = nil;
NSArray *genes = [[[DataManager sharedInstance] mainObjectContext] executeFetchRequest:fetchRequest error:&fetchError];
if (!fetchError)
{
// do stuff with the array.
for (Gene *gene in genes)
{
NSLog(@"%@", gene.acronym);
}
}
else {
NSAssert(!fetchError, @"Failed to fetch data. Aborting.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment