[AnyHashable & Codable : Codable]
expresses the requirement that these types be Codable
, but note that this is not terribly useful as existential Codable
values cannot be encoded or decoded. In order to decode a value, you need to have the concrete type you want — decoding needs to call init(from:)
on a type, and calling (AnyHashable & Codable).init(from:)
isn’t possible since which concrete type would that give you?
It is possible to express an existential AnyEncodable
type, but without knowing your use case better, I wouldn’t recommend doing so unless you really need it, since you run the risk of encoding values you later cannot decode (caveat to this approach).
What are you looking to do here specifically?