问题
I need to get a generic variable for a struct for parsing a JSON
but there is an error that I am getting Type 'BaseJsonModel' does not conform to protocol 'Codable
Below is my struct
struct BaseJsonStruct<T>: Codable {
let info: String
let data: T
}
Error:- Type 'BaseJsonModel' does not conform to protocol 'Codable'
回答1:
T
must also conform to Codable
struct BaseJsonStruct<T : Codable> : Codable {
let info: String
let data: T
}
来源:https://stackoverflow.com/questions/49529208/ios-generic-type-for-codable-property-in-swift