CoreData: error: Failed to call designated initializer on NSManagedObject custom class

前端 未结 2 819
眼角桃花
眼角桃花 2021-01-22 15:14

When I call the function CacheStation I get the error: CoreData: error: Failed to call designated initializer on NSManagedObject class SaveModel. Nothing more nothing less. How

2条回答
  •  悲哀的现实
    2021-01-22 15:32

    Here's what happens:

    1. When you call let sm = SaveModel(); you are creating a new instance of SaveModel.
    2. SaveModel is a subclass of NSManagedObject
    3. NSManagedObject has a designated initializer called init(_: insertIntoManagedObjectContext:)
    4. Your subclass does not add any initializers of any kind, which means that you must call the superclass designated initializer.
    5. You don't do this, so you get an error message which describes the exact problem.

    You need to either call the NSManagedObject designated initializer or create your own designated initializer that calls the superclass designated initializer.

提交回复
热议问题