Please take a look at my code:
No errors
struct Person: Codable {
var name: String
var age: Double
var birthday: Date
var selectedItem: Car
}
struct Car: Codable {
var companyName: String
var creationDate: Date
}
struct iPhone: Codable {
var model: String
var creationDate: Date
var isScreenBroken: Bool = true
}
Build error
struct Person: Codable { // "Type 'Person' does not conform to protocol 'Decodable'", "Type 'Person' does not conform to protocol 'Encodable'"
var name: String
var age: Double
var birthday: Date
var selectedItem: Codable // I've changed this line
}
struct Car: Codable {
var companyName: String
var creationDate: Date
}
struct iPhone: Codable {
var model: String
var creationDate: Date
var isScreenBroken: Bool = true
}
Type 'Person' does not conform to protocol 'Decodable'
Type 'Person' does not conform to protocol 'Encodable'
I don't understand why is this happening. It knows that selectedItem
is conforming to Encodable
& Decodable
:
var selectedItem: Codable
I'm new to protocols in Swift so please when answering try to explain what's happening here.
Thanks!