Navigation Menu

Skip to content

Commit

Permalink
Add the ability to customize the fetched results controller class
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Apr 26, 2012
1 parent a9b4869 commit 7cba2f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions SSManagedViewController.h
Expand Up @@ -17,6 +17,7 @@
@property (nonatomic, strong) SSManagedObject *managedObject; @property (nonatomic, strong) SSManagedObject *managedObject;
@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController; @property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;


+ (Class)fetchedResultsControllerClass;
- (NSFetchRequest *)fetchRequest; - (NSFetchRequest *)fetchRequest;
- (Class)entityClass; - (Class)entityClass;
- (NSArray *)sortDescriptors; - (NSArray *)sortDescriptors;
Expand Down
7 changes: 6 additions & 1 deletion SSManagedViewController.m
Expand Up @@ -18,7 +18,7 @@ @implementation SSManagedViewController


- (NSFetchedResultsController *)fetchedResultsController { - (NSFetchedResultsController *)fetchedResultsController {
if (!_fetchedResultsController) { if (!_fetchedResultsController) {
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:self.fetchRequest _fetchedResultsController = [[[[self class] fetchedResultsControllerClass] alloc] initWithFetchRequest:self.fetchRequest
managedObjectContext:self.managedObjectContext managedObjectContext:self.managedObjectContext
sectionNameKeyPath:self.sectionNameKeyPath sectionNameKeyPath:self.sectionNameKeyPath
cacheName:self.cacheName]; cacheName:self.cacheName];
Expand All @@ -44,6 +44,11 @@ - (void)dealloc {


#pragma mark - Configuration #pragma mark - Configuration


+ (Class)fetchedResultsControllerClass {
return [NSFetchedResultsController class];
}


- (NSFetchRequest *)fetchRequest { - (NSFetchRequest *)fetchRequest {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.entity = [self.entityClass entityWithContext:self.managedObjectContext]; fetchRequest.entity = [self.entityClass entityWithContext:self.managedObjectContext];
Expand Down

0 comments on commit 7cba2f5

Please sign in to comment.