0
votes

I am using XMPP Framework's Core Data message storage and I want to add to my app another Core Data Entity, I create .xcdatamodeld and create Entity, I add code to my AppDelegate, but I get error. Can it be because I use XMPP Framework's Core Data message storage and how to fix it?

 NSManagedObjectContext *context = [self managedObjectContext_messageList];
NSManagedObject *contexNew = [NSEntityDescription insertNewObjectForEntityForName:@"UserProfileEntity" inManagedObjectContext:context];
[contexNew setValue:@1 forKey:@"id"];
[contexNew setValue:@"name TEST" forKey:@"name"];
[contexNew setValue:@"test YEP" forKey:@"test"];
NSError *error;
if ([context save:&error])
{
    NSLog(@"%@", error.description);
}

It crashes on on second line with

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

1

1 Answers

0
votes

That error means that nil is not a legal thing to pass for the managed object context. So, did you inject the context in the correct manner? I mean that the following line

NSManagedObjectContext *context = [self managedObjectContext_messageList];

should have a counterpart like

yourController.managedObjectContext_messageList = theContextYouWantToInject;

or

[yourController setManagedObjectContext_messageList:theContextYouWantToInject];

If you are using segues here a useful discussion: '+entityForName: nil is not a legal NSManagedObjectContext parameter - Core Data.

In addition, are you sure you are providing a valid store coordinator? For further references take a look to The Core Data Stack.