Core Data Error

Discussion in 'iOS Programming' started by xcodeNewbie, Sep 25, 2011.

  1. xcodeNewbie macrumors member

    Jul 1, 2011
    I have a Tab Bar based application and am trying to integrate Core Data into it. I created a navigation based application set up with core data, with the same name as my tab bar application, and copied the App Delegate from there to my tab bar application. I then added a method to retrieve data from my database. When I build and run, xcode gives me an error saying that my persistent store coordinator is nil. However, when I build and run the navigation based app, it gives me an error saying that a fetch request must have an entity. Here is the code I'm using to retrieve data, I'm guessing there's something wrong with it:
     -(void)getData {
        NSManagedObjectContext *context = [self managedObjectContext];
        NSEntityDescription *entity = [NSEntityDescription entityForName:@"History" inManagedObjectContext:context];
        NSFetchRequest *request = [[NSFetchRequest alloc] init];
        [request setEntity:entity];
        NSError *error = nil;
        NSArray *history = nil;
        history = [context executeFetchRequest:request error:&error];
  2. MrFusion macrumors 6502a

    Jun 8, 2005

    This code looks pretty standard. If xCode says it can't find a store or entity, I would check your managedobjectmodel if it really has an entity "History" and appDelegate to see if a context really exists.
  3. xcodeNewbie thread starter macrumors member

    Jul 1, 2011
    Tanks for your advice, I got it working. Turns out the name of my database was inconsistant with the name of the sqlite file it was looking for. All I had to do was rename my database. :)

Share This Page