must call a designated initializer of the superclass NSManagedObject - in swift

Viewed 3379

I get the compiler message: must call a designated initializer of the superclass NSManagedObject (in swift)

//-------------------------------------
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?

2 Answers

In Xcode Version 12.5 (12E262) I would do it like this this:

class abc : NSManagedObject {
    init(x:String, y:String , entity: NSEntityDescription, context: NSManagedObjectContext?){
        super.init(entity: entity, insertInto: context)
        self.x = x
        self.y = y
    }
}
Related