[英]must call a designated initializer of the superclass NSManagedObject - in swift
I get the compiler message: must call a designated initializer of the superclass NSManagedObject (in swift)我收到编译器消息:必须调用超类 NSManagedObject 的指定初始值设定项(快速)
//-------------------------------------
class abc : NSManagedObject {
init(x:String, y:String){
super.init() // <<====== here!!
self.x = x
self.y = y
}
}
//-------------------------------------
the var(s) are declared in the extension xxxx { .... } How to initialize this superclass? var(s) 在扩展名 xxxx { .... } 中声明如何初始化这个超类?
The designated initialiser is指定的初始化程序是
init(entity entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?)
and that is the super init
function you must call.这就是你必须调用的超级
init
函数。
In Xcode Version 12.5 (12E262) I would do it like this this:在 Xcode 版本 12.5 (12E262) 中,我会这样做:
class abc : NSManagedObject {
init(x:String, y:String , entity: NSEntityDescription, context: NSManagedObjectContext?){
super.init(entity: entity, insertInto: context)
self.x = x
self.y = y
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.