Swift Package Index


Codable / [String:Any] bridge


  • The latest stable release is 0.2.0. Released 5 months ago.
  • The last commit to master was 5 months ago.

Swift Version Compatibility

  • 0.2.0 and master
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 0.2.0 and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

DictionaryCoder

A Swift 4 coder/decoder that maps standard types (dictionary, array) to Codable, and vice-versa

Usage

Let's assume we have a Codable type called Simple

Encoding:

let o = Simple(...)
let encoded = try DictionaryCoding().encode(o)
switch encoded {
	case .dictionary(let d): // do something with d
	default: // something went wrong, or maybe Simple is an Array?
}

Decoding:

let d = [...] // dictionary with the RIGHT keys
let o = try DictionaryCoding().decode(Simple.self, from: d)
// o is a Simple, or there was an exception

More info

I took the time to explain the whole process of creating that package in this blog post.

Licence

A long time ago, I went by the licence of people having to offer me a beer if they used the code and met me in real life, but the world is wider now 😉

Instead, this is under CC BY-SA 1.0