18
votes

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

1 Answers

36
votes

T must also conform to Codable

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