Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 看看还有什么数据需要通过解码器解码_Swift_Codable - Fatal编程技术网

Swift 看看还有什么数据需要通过解码器解码

Swift 看看还有什么数据需要通过解码器解码,swift,codable,Swift,Codable,我在一个使用Codable的Swiftt4项目中工作。但是,我得到了以下错误: No value associated with key CodingKeys(stringValue: "postable_type", intValue: nil) ("postable_type"). 现在我想知道的是如何最好地调试它。是否有可能看到Codable试图在我的模型中填充什么数据?特别是因为在这种情况下,它使用了相当先进的嵌套,我相信它会是一个真正的救命恩人在这里 谢谢:)Codable错误非常具

我在一个使用Codable的Swiftt4项目中工作。但是,我得到了以下错误:

No value associated with key CodingKeys(stringValue: "postable_type", intValue: nil) ("postable_type").
现在我想知道的是如何最好地调试它。是否有可能看到Codable试图在我的模型中填充什么数据?特别是因为在这种情况下,它使用了相当先进的嵌套,我相信它会是一个真正的救命恩人在这里


谢谢:)

Codable
错误非常具有描述性。要进行调试,请使用此
catch
块获取详细的错误消息:

} catch DecodingError.dataCorrupted(let context) {
    print(context)
} catch DecodingError.keyNotFound(let key, let context) {
    print("Key '\(key)' not found:", context.debugDescription)
    print("codingPath:", context.codingPath)
} catch DecodingError.valueNotFound(let value, let context) {
    print("Value '\(value)' not found:", context.debugDescription)
    print("codingPath:", context.codingPath)
} catch DecodingError.typeMismatch(let type, let context)  {
    print("Type '\(type)' mismatch:", context.debugDescription)
    print("codingPath:", context.codingPath)
} catch {
    print("error: ", error)
}

debugDescription
codingPath
都能准确地告诉您错误所在。

Codable
错误非常具有描述性。要进行调试,请使用此
catch
块获取详细的错误消息:

} catch DecodingError.dataCorrupted(let context) {
    print(context)
} catch DecodingError.keyNotFound(let key, let context) {
    print("Key '\(key)' not found:", context.debugDescription)
    print("codingPath:", context.codingPath)
} catch DecodingError.valueNotFound(let value, let context) {
    print("Value '\(value)' not found:", context.debugDescription)
    print("codingPath:", context.codingPath)
} catch DecodingError.typeMismatch(let type, let context)  {
    print("Type '\(type)' mismatch:", context.debugDescription)
    print("codingPath:", context.codingPath)
} catch {
    print("error: ", error)
}

debugDescription
codingPath
都会准确地告诉您错误所在和位置。

请注意,如果所有关联的值都是常量,您也可以将其写入:
catch let DecodingError.typeMismatch(类型、上下文)
请注意,如果所有关联值都是常量,也可以将其写成:
catch let DecodingError.typemissmatch(type,context)