J'utilise Realm avec Object Mapper pour l'analyse JSON. Lorsque je crée une classe de modèle qui utilise à la fois l'objet Mapper et Realm que je reçois erreur de compilationImpossible d'utiliser le domaine avec le mappeur d'objets swift 3.0
error:must call a designated initializer of the superclass 'QuestionSet'
import ObjectMapper
import RealmSwift
class QuestionSet: Object, Mappable {
//MARK:- Properties
dynamic var id:Int = 0
dynamic var title:String?
dynamic var shortTitle:String?
dynamic var desc:String?
dynamic var isOriginalExam:Bool = false
dynamic var isMCQ:Bool = false
dynamic var url:String?
//Impl. of Mappable protocol
required convenience init?(map: Map) {
self.init()
}
//mapping the json keys with properties
public func mapping(map: Map) {
id <- map["id"]
title <- map["title"]
shortTitle <- map["short_title"]
desc <- map["description"]
isMCQ <- map["mc"]
url <- map["url"]
isOriginalExam <- map["original_pruefung"]
}
}
si j'utilise super.init() dans la méthode init que je reçois l'erreur de compilation
cas 1:
//Impl. of Mappable protocol
required convenience init?(map: Map) {
self.init()
}
error:must call a designated initializer of the superclass 'QuestionSet'
Cas n ° 2:
//Impl. of Mappable protocol
required convenience init?(map: Map) {
super.init()
}
Convenience initializer for 'QuestionSet' must delegate (with 'self.init') rather than chaining to a superclass initializer (with 'super.init')
Cas n ° 3:
//Impl. of Mappable protocol
required convenience init?(map: Map) {
super.init()
self.init()
}
error 1: must call a designated initializer of the superclass 'QuestionSet'
Initializer cannot both delegate ('self.init') and chain to a superclass initializer ('super.init')
Convenience initializer for 'QuestionSet' must delegate (with 'self.init') rather than chaining to a superclass initializer (with 'super.init')
Vous avez besoin d'un constructeur par défaut ou quelle que soit votre langue (Swift) l'appelle. – EpicPandaForce
@EpicPandaForce Si j'utilise la méthode init() par défaut que je dois implémenter les méthodes init restantes de Object. Que je ne veux pas mettre en œuvre. Donc, ici, la commodité init() est utilisée –
Hmm ... alors je ne suis pas sûr. Ignorez-moi, Swift n'est pas mon fort: D – EpicPandaForce