When you will get this error?
It’s a very common error who just started using Core Data in their iOS development journey. It comes when you create an instance of the Core Data class. e.g.
var items = Item() //Here Item is a Core Data class.
Reason for this error
In Core Data, Creating a direct instance of the Class is not allowed. We must use the designated initializer. e.g.
Item(context: NSManagedObjectContext)
or
Item(entity: NSEntityDescription, insertInto: NSManagedObjectContext?)
Solution for this error
Don’t create a direct instance of the Core Data Class.
1) Create an instance using the designated initializer
OR
2) Create an Optional type, if you are not using the object right away.
var
Sergio says
It was really helpful for a newbie, I am commenting to validate this response, so people who finds this answer believes in its veracity.