【问题标题】:Issues calling super method in ObjectMapper在 ObjectMapper 中调用超级方法的问题
【发布时间】:2016-09-24 05:01:19
【问题描述】:

正在尝试将 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 方法??
  • ObjectMapper 的版本是多少?您收到编译器错误或运行时错误?
  • @wint 2,0 版。编译器错误。

标签: ios swift objectmapper


【解决方案1】:

我认为你不见了:

init() {
    super.init()
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    • 2011-06-03
    • 1970-01-01
    • 2012-09-10
    • 1970-01-01
    • 2013-08-09
    相关资源
    最近更新 更多