Swift CoreData: error: Failed to call designated initializer on NSManagedObject class 'NSManagedObject'

蹲街弑〆低调 提交于 2019-11-29 10:58:13

The dedicated initializer is

class func insertNewObjectForEntityForName(_ entityName: String!,
   inManagedObjectContext context: NSManagedObjectContext!) -> AnyObject!

Clearly, you are not inserting a new object, so you really want an optional value. Maybe you declared your class variable managedObject as NSManagedObject!? Try setting it to NSManagedObject? and also change the operator to as?.

An entity in CoreData is equivalent to a class. Did you add the entity to your managed object model, and subclass the entity? (Check out the programming guide for a fuller background.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!