Manuel Zompetta
Manuel Zompetta

Reputation: 414

Swift struct with tuples does not conform to Codable

I'm trying to make a struct with optionals Codable/Decodable but I receive the error message:

Type 'item' does not conform to protocol 'Encodable'

Here is the code:

struct Item: Codable {
    let domanda: String
    let rispostaSemplice: Int?
    var rispostaComplessa: [(testoRisposta: String, valoreRisposta: Bool)]?
}

How can I make the tuple [(testoRisposta: String, valoreRisposta: Bool)]? conform?

Upvotes: 1

Views: 351

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100503

You need

struct Item: Codable {
  let domanda: String
  let rispostaSemplice: Int?
  var rispostaComplessa: [InnerItem]?
}

struct InnerItem: Codable { 
   var testoRisposta: String
   var valoreRisposta: Bool
}

Upvotes: 3

Related Questions