According to the NSManagedObject
class reference:
Important: This method is the designated initializer for NSManagedObject. You must not initialize a managed object simply by sending it init.
The method of reference in the above quoted text is insertNewObjectForEntityForName:inManagedObjectContext:
and can be used thusly:
NSManagedObject *object = [NSEntityDescription
insertNewObjectForEntityForName:@"Item"
inManagedObjectContext:context];
EDIT (In response...)
This code is just plain wrong:
TaskTypeEntity *taskTypeEntity = [TaskTypeEntity alloc];
Even if TaskTypeEntity
were not a NSManagedObject
it would still be wrong, as you never called an initializer.
The fact that it is a NSManagedObject
makes it even more wrong, because you are never supposed to alloc/init one of those.
Why not try something like this (I assume you are using transformable attributes for image and color):
+ (instancetype)taskTypeEntityInMOC:(NSManagedObjectContext*)context
name:(NSString*)name
image:(UIImage*)image
color:(UIColor*)color
{
TaskTypeEntity *taskTypeEntity = [NSEntityDescription insertNewObjectForEntityForName:ENTITY_NAME inManagedObjectContext:content];
taskTypeEntity.name = name;
taskTypeEntity.image = image;
taskTypeEntity.color = color;
return taskTypeEntity;
}
Then you can call it...
TaskTypeEntity *taskTypeEntity =
[TaskTypeEntity taskTypeEntityInMOC:context
name:(NSString*)name
image:(UIImage*)image
color:(UIColor*)color];