Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xcodeNewbie

macrumors member
Original poster
Jul 1, 2011
65
0
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:
Code:
 -(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];
}
 
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:
Code:
 -(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];
}


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.
 
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. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.