With Core Data, I am able to save and fetch objects in memory; however, when I restart my app (in the simulator) and fetch the results, the object is fetched but all the attributes are nil. I have included all protocol methods in my appdelegate and having initialized my managedObjectContext as such:
managedObjectContext = [self managedObjectContext];
in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Here is what I am getting in the logs...
Correct: Fetching results log (app not restarted) --> Name: new entry!!!!
Incorrect: Fetching results log (app restarted) --> Name: (null) -But, object still exists in persistantStore
--
//Save entry
Entry *entry = (Entry *)[NSEntityDescription insertNewObjectForEntityForName:@"Entries" inManagedObjectContext:managedObjectContext];
[entry setTitle:@"new entry!!!!"];
NSError *error;
if(![managedObjectContext save:&error]){
NSLog(@"SAVE ERROR!!!");
}
//Fetch entry
NSError *error;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Entries" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *info in fetchedObjects) {
NSLog(@"Name: %@", [info valueForKey:@"title"]);
}