Swiftpack.co - Package - elegantchaos/DictionaryCoding


This is an implementation of Swift's Encoder/Decoder protocols which uses NSDictionary as its underlying container mechanism.

It allows you to take a native swift class or struct that confirms to the Codable protocol and convert it to, or initialise it from, a dictionary.

A lot of the code is actually taken from the Swift Foundation library's own JSONEncoder and JSONDecoder classes.

It turns out that those class actually work by using NSDictionary as an intermediate step between JSON and the native type to be encoded/decoded. Unfortunately the underlying NSDictionary support isn't exposed by Foundation, which is why I've done so here.

See this blog post for a bit more detail!

Build Instructions

At the moment this module is best built using the Swift Package Manager with swift build.

The unit tests can be run with swift test.

An Xcode project can be generated with swift package generate-xcodeproj --xcconfig-overrides DictionaryCoding.xcconfig.

A CocoaPods .podspec file is included. I don't use CocoaPods myself though, so I can't be entirely sure that I haven't broken something (or forgotten to update something).

Please file issues (or even better, pull requests) for support for other build systems.


Stars: 88


Used By

Total: 0


1.0.7 - 2019-11-26 12:32:53

Update to Swift 5 (mostly so that I can use the 5.0 package tools format, and specify minimum os versions in the Packages.swift file).

Fixed a few Swift 5.0 warnings.

Added GitHub Actions support to the project. This will probably replace Travis when I get it playing nice with my general workflow.

1.0.6 - 2019-01-15 16:20:51

Fixed a minor warning that Cocoapods was complaining about.

1.0.5 - 2019-01-14 11:01:51

Updated podspec version no.

1.0.4 - 2019-01-11 13:01:13

Enables iOS support for the podspec. Uses compactMap when available.

1.0.3 - 2018-03-12 18:19:42

Adds a podspec for use with Cocoapods.

1.0.2 - 2018-02-22 22:25:32

More flexible handling of default values. Better support for decoding URL and UUID items.

1.0.1 - 2018-02-21 18:18:46

More unit tests. Travis-CI integration. Added the ability to have missing values filled in from defaults.

1.0.0 - 2018-02-20 15:09:49

First version.