Created
April 4, 2011 01:27
-
-
Save yeonsh/901016 to your computer and use it in GitHub Desktop.
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
-(BOOL) setupFetchedResultsControllerForEntity:(NSString *)argEntityName withSortKey:(NSString *)argSortKey | |
{ | |
// Uncomment the following line to display an Edit button in the navigation bar for this view controller. | |
// self.navigationItem.rightBarButtonItem = self.editButtonItem; | |
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; | |
// Configure the request's entity, and optionally its predicate. | |
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:argEntityName inManagedObjectContext:self.managedObjectContext]; | |
[fetchRequest setEntity:entityDescription]; | |
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:argSortKey ascending:NO]; | |
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; | |
[fetchRequest setSortDescriptors:sortDescriptors]; | |
[sortDescriptors release]; | |
[sortDescriptor release]; | |
self.fetchedResultsController = [[NSFetchedResultsController alloc] | |
initWithFetchRequest:fetchRequest | |
managedObjectContext:self.managedObjectContext | |
sectionNameKeyPath:nil | |
cacheName:nil]; | |
[self.fetchedResultsController setDelegate:self]; | |
[fetchRequest release]; | |
NSError *error; | |
BOOL success = [self.fetchedResultsController performFetch:&error]; | |
if (success) { | |
T_DBG(@"fetch succeeded."); | |
return YES; | |
} | |
else { | |
T_DBG(@"fetch failed"); | |
return NO; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment