Any when decoding JSON with Codable?

后端 未结 4 1917
情深已故
情深已故 2020-12-06 08:32

With Swift 3 JSONSerialization, if a part of your data model was completely dynamic, you could always just leave the deserialized data at Any and l

4条回答
  •  失恋的感觉
    2020-12-06 09:17

    Simply you can use AnyCodable type from Matt Thompson's cool library AnyCodable.

    Eg:

    import AnyCodable
    
    struct Foo: Codable
    {
        var bar: AnyCodable
    }
    

提交回复
热议问题