William Falcon
William Falcon

Reputation: 9813

error while adding to core data

I am trying to add an entry through core data and I am running into an error here:

PastTickets is my managed object

However when I do line two here it crashes:

PastTickets *newTicket;
    newTicket = (PastTickets *)[NSEntityDescription insertNewObjectForEntityForName:@"PastTickets" inManagedObjectContext:_managedObjectContext];

This is my crash error

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

it looks ok in the model:

THank you in advance enter image description here

Upvotes: 0

Views: 48

Answers (1)

Tom Harrington
Tom Harrington

Reputation: 70936

The error doesn't complain about the entity name-- it's telling you that _managedObjectContext is nil, and that you're not allowed to pass nil for that argument. You're reaching this line in your code without first creating the managed object context. You need to rearrange things so that the context exists before you start inserting new managed objects.

Upvotes: 1

Related Questions