に準拠したコンテナ タイプを実装したいのですCodable
が、少し問題が発生しています。コンテナをジェネリック化して、エンコード可能およびデコード可能な要素を保持したいと考えています。当初、私はこれを持っていました:
struct Container: Codable {
var identifier: String
var element: Any
}
...しかし、ある種の型安全性を確保できるように変更しました。誰かがここで何が起こっているのか正確に説明できますか?
マイコード
struct Container: Codable {
var identifier: String
var element: Codable
}
コンパイラ出力
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
...