Core Data - fetchedResultsController Setup

I am getting the following error when I try to call my fetchResultsController method.  I have put some of the code below.  This app is a navigation app.  

Error:
warning: 'listTableViewController' may not respond to '-fetchedResultsController'
.....
error: 'error' undeclared (first use in function)





#import <UIKit/UIKit.h>
@class iListNavController;

@interface iMasterAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
      IBOutlet UITabBarController *rootController;
      IBOutlet ListNavController *listNavController;
      
      /*** Used for Core Data ****/
      NSManagedObjectModel *managedObjectModel;
    NSManagedObjectContext *managedObjectContext;         
    NSPersistentStoreCoordinator *persistentStoreCoordinator;
      NSFetchedResultsController *fetchedResultsController;
      
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *rootController;
@property (nonatomic, retain) IBOutlet ListNavController *listNavController;

@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;

- (NSString *)applicationDocumentsDirectory;
- (NSString *)documentsFolder;
- (NSFetchedResultsController *)fetchedResultsController;
-(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)object atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath;
@end


Then in my ListTableViewController.m file I have the following pieces:
@synthesize listDetailViewController;



- (void)viewDidLoad {
    [super viewDidLoad];

      if(![[self fetchedResultsController] performFetch:&error])
      {
                  
      }
      
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
justanothercoderAsked:
Who is Participating?
 
pgnatyukConnect With a Mentor Commented:
- (NSFetchedResultsController *)fetchedResultsController;
Are you sure you need this method in the class interface?
 
You need to create the instance of NSFetchedResultsController first:
NSFetchedResultsController *fetchedResultsController = [[NSFetchedResultsController alloc] init...]
0
 
justanothercoderAuthor Commented:
I am not sure.  I am trying to follow an example in a book.  This is what I have in the AppDelegate.m file. So the fetchedResultsController should be instatiated.    

- (NSFetchedResultsController *)fetchedResultsController
{
      if(fetchedResultsController != nil)
            return fetchedResultsController;
      
      
      NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
      
      NSEntityDescription *entity = [NSEntityDescription entityForName:@"Local"
                                                                    inManagedObjectContext:managedObjectContext];
      
      [fetchRequest setEntity:entity];
      [fetchRequest setFetchBatchSize:20];
      
      NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
                                                            initWithKey:@"CreatedDtTm" ascending:NO];
      
      NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
      
      [fetchRequest setSortDescriptors:sortDescriptors];
      
      NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
                        managedObjectContext:managedObjectContext sectionNameKeyPath:nil
                        cacheName:@"Root"];
      
      aFetchedResultsController.delegate = self;
      self.fetchedResultsController = aFetchedResultsController;
      
      [aFetchedResultsController release];
      [fetchRequest release];
      [sortDescriptor release];
      [sortDescriptors release];
      
      return fetchedResultsController;
}
0
 
pgnatyukCommented:
And I wrote how to instantiate it in my previous comment. So it works now?

0
All Courses

From novice to tech pro — start learning today.