说我有一个带有原始值的枚举,例如:
enum Foo: String,Codable {
case bar
}
由于某种原因,我需要对其进行编码,然后再对数据进行解码。以下是我如何对其进行编码/解码
let data = try! JSONEncoder().encode(Foo.bar)
let foo = try! JSONDecoder().decode(Foo.self,from: data)
这在iOS 13上运行良好,但在iOS 12上出现错误。
The data couldn't be written because it isn't in the correct format.
有没有建议在iOS 12上解决此问题?