ios - 在 ObjectMapper 中调用 super 方法的问题

标签 ios swift objectmapper

尝试将 ObjectMapper 语法转换为 Swift 3.0:

class CustomJsonResponse: Mappable {

    var status: String?
    var response: String?
    var errorCode: CustomErrorCode?

    init() {

    }

    required init?(map: Map) {

    }

    func mapping(map: Map) {
        status <- map["status"]
        response <- map["response"]
        errorCode <- (map["error_code"], CustomErrorCodeTransform())
    }
}

class CustomChallengesResponse: CustomJsonResponse {

    var challenges: [CustomChallenge]?

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

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

        challenges <- map["data.questions"]
    }
}

我在以下位置遇到错误:

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

“必需的初始化程序必须由 CustomJsonResponse 的子类提供”

我在这里做错了什么?对此的任何指示都会很棒。谢谢!

最佳答案

我想你错过了:

init() {
    super.init()
}

关于ios - 在 ObjectMapper 中调用 super 方法的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39672710/

相关文章:

ios - 以编程方式设置 UITableView 行选择返回 nil

ios - coreData 中的关系如何运作

ios - 子类上无继承导出

ios - SWIFT 删除 subview

ios - Swift iOS API Controller 停止工作

java - ObjectMapper ConvertValue 错误 java.util.ArrayList[0]->java.util.LinkedHashMap ["id"]

java - 是否可以获取到@JsonProperty 的原始字段名?

ios - 插入 Collection View 单元格后是否可以重复使用?

Swift 常量 : Struct or Enum

ios - 将密码学与 ObjectMapper 结合使用