How come I can cast to NSManagedObject but not to my entity's type?

后端 未结 8 1468
粉色の甜心
粉色の甜心 2020-12-01 13:36

I\'m using the Swift boilerplate code for Core Data in a fresh project. My .xcdatamodeld file has a single entity defined (Task) with a single attr

相关标签:
8条回答
  • 2020-12-01 14:30

    I had to add the @objc() and set the class in the coredata interface. In the CoreData right window, in the Entity area, there are Name and Class textbox. Class must not be MSManagedObject but instead your class. I created a simple working example!

    0 讨论(0)
  • 2020-12-01 14:33

    Make sure your Class name field is actually Module.Task, where Module is the name of your app. CoreData classes in Swift are namespaced. Right now, your object is being pulled out of the context as an NSManagedObject, not as a Task, so the as-cast is failing.

    0 讨论(0)
提交回复
热议问题