How to use Any in Codable Type

后端 未结 11 757
猫巷女王i
猫巷女王i 2020-11-29 04:20

I\'m currently working with Codable types in my project and facing an issue.

struct Person: Codable
{
    var id: Any
}

11条回答
  •  日久生厌
    2020-11-29 05:21

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

    Eg:

    import AnyCodable
    
    struct Person: Codable
    {
        var id: AnyCodable
    }
    

提交回复
热议问题