utahiosmac / Marshal

Marshaling the typeless wild west of [String: Any]
MIT License
697 stars 62 forks source link

Support coding keys #127

Closed olejnjak closed 6 years ago

olejnjak commented 6 years ago

Hello,

I love using Marshal as it is much simpler than swift's Codable. But very often I want to serialize and deserialize my objects using the same keys. So I was always creating enums so the keys are kept on a single place.

And I was wondering why I need to write that when conforming to Codable does that for me automatically. So i thought it would be nice if Marshal supported using CodingKeys.

I had two ideas

  1. add variants of value(for:) methods with CodingKey variant
  2. substitute KeyType for CodingKey

I went for variant 2 as it made more sense for me. At first I wanted to say that every CodingKey is also a KeyType as KeyType requires just a stringValue which is a subset of what CodingKey requires. This was no way as the compiler doesn't allow protocol inheritace in this way.

Well then I removed custom KeyType and converted it to CodingKey.

gaming-hacker commented 6 years ago

seems reasonable to be, i forked and pulled in your PR, i think the build bombed because of an xcode setting.