• C

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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pgnatyukCommented:
- (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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.