Created
May 30, 2011 07:29
-
-
Save shannoga/998559 to your computer and use it in GitHub Desktop.
Core data fetch function
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
+(NSArray*)fetchForCardsEntity:(NSString*)entityName withPredicate:(NSString*)predicateFormat withSortDiscriptor:(NSString*)sortdDscriptorName{ | |
NSManagedObjectContext *moc=[[self appDelegate] managedObjectContext]; | |
NSEntityDescription *entityDescription; | |
NSPredicate *predicate; | |
NSFetchRequest *request = [[NSFetchRequest alloc] init]; | |
entityDescription = [NSEntityDescription entityForName:entityName inManagedObjectContext:moc]; | |
[request setEntity:entityDescription]; | |
predicate = [NSPredicate predicateWithFormat: predicateFormat]; | |
[request setPredicate:predicate]; | |
if (sortdDscriptorName) { | |
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] | |
initWithKey:sortdDscriptorName ascending:YES]; | |
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]]; | |
[sortDescriptor release]; | |
} | |
NSError *error = nil; | |
NSArray * requestArray =[moc executeFetchRequest:request error:&error]; | |
if (requestArray == nil) | |
{ | |
// Deal with error... | |
} | |
[request release]; | |
return requestArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment