2016-09-24 121 views
1

試圖ObjectMapper語法轉換爲雨燕3.0:問題調用父類方法在ObjectMapper

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「

我在做什麼錯在這裏?任何指針都會很棒。謝謝!

+0

什麼是地圖,是它的模型對象? 如果是這樣你實現了任何init方法? – Janmenjaya

+0

ObjectMapper的版本是什麼?你得到編譯器錯誤或運行時錯誤? – wint

+0

@wint版本2,0。編譯器錯誤。 – KexAri

回答

0

我認爲你缺少:

init() { 
    super.init() 
}