-1

Here is my model class

struct ErrorData: Decodable {
    let code : Int
    let message : String
    let data : [ErrorDataFields]
}

i want to have ErrorDataFields to be array and object like

struct ErrorData: Decodable {
        let code : Int
        let message : String
        let data : [ErrorDataFields]
    }

AND

struct ErrorData: Decodable {
        let code : Int
        let message : String
        let data : ErrorDataFields
    }
Midhun Narayan
  • 829
  • 2
  • 9
  • 26

1 Answers1

0

We can use a generic type with Decodable. Only thing is the generic type should also conform to Decodable.

struct ErrorData <T : Decodable> : Decodable {
    let code : Int
    let message : String
    let data : T
}

Manav
  • 2,284
  • 1
  • 14
  • 27