# How do I declare an all-encompassing Codable Dictionary?

**URL:** <https://forums.swift.org/t/how-do-i-declare-an-all-encompassing-codable-dictionary/12910>\
**Category:** Using Swift\
**Tags:** codable\
**Created:** [May 23, 2018, 4:24am UTC](https://forums.swift.org/t/how-do-i-declare-an-all-encompassing-codable-dictionary/12910 "2018-05-23T04:24:43Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![itaiferber](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/itaiferber/32/33840_2.png) [@itaiferber](https://forums.swift.org/u/itaiferber)\
**Post date:** [May 23, 2018, 5:17am UTC](https://forums.swift.org/t/how-do-i-declare-an-all-encompassing-codable-dictionary/12910/2 "2018-05-23T05:17:25Z")

</div>

`[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](https://forums.swift.org/t/how-to-encode-objects-of-unknown-type/12253/5), 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](https://forums.swift.org/t/how-to-encode-objects-of-unknown-type/12253/9)).

What are you looking to do here specifically?

---

_[View the full topic](https://forums.swift.org/t/how-do-i-declare-an-all-encompassing-codable-dictionary/12910)._
