Alamofire.request(todoEndpoint)
.responseJSON { response in
switch response.result {
case .success(let JSON):
let response: ETOOperatorsList = JSON as! ETOOperatorsList
delegate.requestWithReference(requestReference: "112", model: response as AnyObject)
case .failure(let error):
delegate.requestWithReference(requestReference: "112", error: error)
}
}
无法投放错误
“无法将'__NSDictionaryI'类型的值强制转换为'OperatorsList'。”
如何将Alamofire responseJSON
强制转换为自定义对象?
谢谢!
答案 0 :(得分:0)
Apple没有提供OJM(Object / Json Mapper)数据绑定功能,将PONSO转换为JSON,反之亦然。您可以进行手动映射,也可以使用某些第三方映射。例如
https://github.com/Hearst-DD/ObjectMapper https://github.com/tristanhimmelman/AlamofireObjectMapper