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'
1 个解决方案
#1
12
T
must also conform to Codable
T还必须符合Codable
struct BaseJsonStruct<T : Codable> : Codable {
let info: String
let data: T
}
#1
12
T
must also conform to Codable
T还必须符合Codable
struct BaseJsonStruct<T : Codable> : Codable {
let info: String
let data: T
}