0
我最近試圖使用可解碼協議將JSON解析爲模型,並且我已成功完成該任務。但是現在我想用RxSwift實現雙向綁定。爲此,我需要聲明類型的變量的變量<>「這裏是我的模型片段:使用swift 4可解碼協議和RxSwift
struct Person : Decodable
{
var batchcomplete = String()
var `continue` = Continue()
var query = Query()
var limits = Limit()
enum CodingKeys: String,CodingKey
{
case batchcomplete
case `continue`
case limits
case query
}
init(from decoder: Decoder) throws
{
let container = try decoder.container(keyedBy: CodingKeys.self)
batchcomplete = try container.decode(String.self, forKey: .batchcomplete)
`continue` = try container.decode(Continue.self, forKey: .`continue`)
limits = try container.decode(Limit.self, forKey: .limits)
query = try container.decode(Query.self, forKey: .query)
}
}
現在,如果我從字符串()改變我的「batchcomplete」到變量時,init()方法引發錯誤:
No 'decode' candidates produce the expected contextual result type 'Variable<String>'.
進行這些更改,您將收到錯誤消息。
var batchcomplete = Variable<String>("")
batchcomplete = try container.decode(Variable<String>.self, forKey: .batchcomplete)
非常感謝:-) – Reckoner