Created
April 10, 2012 20:08
-
-
Save jackhl/2354122 to your computer and use it in GitHub Desktop.
core data fetch
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
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