I want to implement a container type that conforms to Codable
, but am running into a bit of an issue. I want to genericize my container to hold any element that can be Encodable & Decodable. Initially, I had this:
struct Container: Codable {
var identifier: String
var element: Any
}
...but changed it so that I could have some sort of type safety. Can someone explain what exactly is going on here?
My Code
struct Container: Codable {
var identifier: String
var element: Codable
}
Compiler Output
Playground execution failed:
MyPlayground.playground:3:9: note: cannot automatically synthesize 'Decodable' because 'Codable' (aka 'Decodable & Encodable') does not conform to 'Decodable'
var element: Codable
...