Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift ObjectMapper-初始化子类中的空init_Swift_Objectmapper - Fatal编程技术网

Swift ObjectMapper-初始化子类中的空init

Swift ObjectMapper-初始化子类中的空init,swift,objectmapper,Swift,Objectmapper,我有一个名为“base”的基类,它实现了可映射协议。我已经对该类进行了子类化,如下所述 class Base: Mappable { var base: String? required init?(map: Map) { } func mapping(map: Map) { base <- map["base"] } } class Subclass: Base { var sub: String? req

我有一个名为“base”的基类,它实现了可映射协议。我已经对该类进行了子类化,如下所述

class Base: Mappable {
    var base: String?

    required init?(map: Map) {

    }

    func mapping(map: Map) {
        base <- map["base"]
    }
}

class Subclass: Base {
    var sub: String?

    required init?(map: Map) {
        super.init(map: map))
    }

    override func mapping(map: Map) {
        super.mapping(map: map)

        sub <- map["sub"]
    }
}
您可以在
基类中添加
init()
,在
子类中添加
override init()

class Base: Mappable {
    var base: String?

    init() {}

    required init?(map: Map) {

    }

    func mapping(map: Map) {
        base <- map["base"]
    }
}

class Subclass: Base {
    var sub: String?

    override init() {
        super.init()
    }

    required init?(map: Map) {
        fatalError("init(map:) has not been implemented")
    }

    override func mapping(map: Map) {
        super.mapping(map: map)

        sub <- map["sub"]
    }
}
类基:可映射{
var-base:String?
init(){}
必需的初始化?(映射:映射){
}
func映射(映射:映射){
base您可以在
base
中添加
init()
,在
子类中添加
override init()

class Base: Mappable {
    var base: String?

    init() {}

    required init?(map: Map) {

    }

    func mapping(map: Map) {
        base <- map["base"]
    }
}

class Subclass: Base {
    var sub: String?

    override init() {
        super.init()
    }

    required init?(map: Map) {
        fatalError("init(map:) has not been implemented")
    }

    override func mapping(map: Map) {
        super.mapping(map: map)

        sub <- map["sub"]
    }
}
类基:可映射{
var-base:String?
init(){}
必需的初始化?(映射:映射){
}
func映射(映射:映射){

base为什么您不能?我感觉这个问题缺少一些信息。@JoakimDanielson我没有遗漏任何信息,每当我尝试这个问题时,我都会得到调用中参数“map”的
缺少参数
我没有说您的代码中缺少任何信息,而是说关于这个问题的信息,以便我们能够完全理解理解它。看着被接受的答案,我认为它与
Mappable
有关,但为什么你不能?我感觉这个问题中缺少了一些信息。@JoakimDanielson我没有遗漏任何东西,每当我尝试这个,我都会在call中得到
缺少参数“map”的参数假设您的代码中缺少任何内容,而是关于问题的信息,以便我们能够完全理解。查看已接受的答案,我认为它与
Mappable
though有关,但它不允许我将对象创建为
var obj=Subclass()
@MuhammadArifulIslam您使用的ObjectMapper版本是什么?@MuhammadArifulIslam不要忘记将
init(){}
添加到
Base
override init(){super.init()}
子类
?您可以用我的代码替换代码。我已经测试过它,我可以将空的子类声明为
var Subclass=Subclass>()
如@RomanPodymov中所示,我以前用过它,但没有用,现在在清理和构建它的工作之后。非常感谢。但是它不允许我创建对象,因为
var obj=Subclass()
@MuhammadArifulIslam您使用什么ObjectMapper版本?@MuhammadArifulIslam别忘了添加
init(){}
Base
重写init(){super.init()}
子类
?您可以用我的代码替换您的代码。我已经测试了它,我可以将空子类声明为
var Subclass=Subclass()
如@RomanPodymov中所示,我以前用过它,但没有用,现在在清理和构建它之后,它可以用了。非常感谢。