我在CDModel.xcdatamodeld中创建了一个简单的实体’CDWorkout’,其中一个属性’name’. AppDelegate中的容器名称也是“CDModel”. “CDWorkout”的类Codegen是类别/扩展名.这是CDWorkout类的代码:
class CDWorkout: NSManagedObject { class func createWorkout(workoutInfo : Workout,in context: NSManagedObjectContext) -> CDWorkout{ let workout = CDWorkout(context: context) workout.name = "anyName" return workout } }
createWorkout函数从另一个viewController调用,上下文参数为container.viewContext但它立即崩溃并显示消息:
Terminating app due to uncaught exception ‘NSInvalidArgumentException’,reason: ‘An NSManagedObject of class ‘Workout_Generator.CDWorkout’ must have a valid NSEntityDescription.’
我忘记了什么?
问题是我没有检查类模块:CDWorkout Entity的当前产品模块.
原文链接:https://www.f2er.com/swift/319583.html