简体   繁体   English

iOS Swift中可编码属性的通用类型

[英]iOS Generic type for codable property in Swift

I need to get a generic variable for a struct for parsing a JSON 我需要获取一个用于解析JSON的结构的泛型变量

but there is an error that I am getting Type 'BaseJsonModel' does not conform to protocol 'Codable 但是我得到的错误类型'BaseJsonModel'不符合协议'Codable

Below is my struct 下面是我的结构

  struct BaseJsonStruct<T>: Codable {
    let info: String
    let data: T
 }

Error:- Type 'BaseJsonModel' does not conform to protocol 'Codable' 错误: - 类型'BaseJsonModel'不符合协议'Codable'

T must also conform to Codable T还必须符合Codable

struct BaseJsonStruct<T : Codable> : Codable {
    let info: String
    let data: T
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM