When you do this:
[NSEntityDescription entityForName:@"trainingDay" inManagedObjectContext:self.context];
What you get is an instance of NSEntityDescription
. This is an object that is equivalent to the entity type that you configured in the Core Data model editor in Xcode. It represents an entity type, not an instance of that entity.
From the error message it appears that trainingDayObject
is declared as VitTrainingDay *
, which is a pointer to an instance of a managed object.
The difference here is exactly the same idea as the difference between a class and an instance of a class. It's like you're trying to assign the NSString
class to something that's supposed to be a specific instance of a string.
What you actually want is something like
trainingDayObject = [NSEntityDescription insertNewObjectForEntityForName:@"trainingDay" inManagedObjectContext:self.context];
Because this method creates a new instance of the entity type, instead of just giving you the entity type object itself.