0

I am struggline with adding data into core data and retrieving. It seems like this code should work but it is throwing an error seen in my title. I'm basically getting data from NSUserDefaults and trying to write that into my core data.

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *sellTitle = [defaults objectForKey:@"sellTitle"];

Item *item = (Item *)[NSEntityDescription insertNewObjectForEntityForName:@"Item" inManagedObjectContext:managedObjectContext];

[item setValue:sellTitle forKey:@"title"];
NSError *error;
if (![managedObjectContext save:&error]);
        NSLog(@"Failed to add all the data: %@", [error domain]);

+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Item''

Any idea why? I have tried some of the solutions found in here but nothing is working. For example, i have attempted to implment this into AppDelegate but i'm still getting a nil return on my ManagedObjectContext. Thank you!

mreynol
  • 309
  • 3
  • 17
  • If `managedObjectContext` is nil you could single-step in the debugger through the managed object creation functions and see where it fails. – Martin R Nov 12 '12 at 22:15
  • Thank you. Its crazy now. I've managed to get it to save to Core Data. I can see via some NSLogs i put into my AppDelegate. However, I can't for the life of me get it to Fetch in another table view controller. I still get the same error. With the above code, changed to get from app delegate, but for some reason the same isn't working for the fetch. – mreynol Nov 13 '12 at 00:14

0 Answers0