I use this pattern to group the keys that I use in a Decodable type:
struct MyDecodableType: Decodable {
enum Keys: KeyPath {
case foo = "foo"
case bar = "bar"
}
}
I used to make those Keys enum have an associated String value, but with the switch to KeyPath, in order to be able to use KeyPath as the raw value of an enum, it needs to conform to Equatable.
I use this pattern to group the keys that I use in a
Decodable
type:I used to make those
Keys
enum have an associatedString
value, but with the switch toKeyPath
, in order to be able to useKeyPath
as the raw value of an enum, it needs to conform toEquatable
.