[Deprecated] The easy to use Swift JSON decoder
This version moves Unbox to Xcode 10.2 and Swift 5, and with that comes some API changes that will require manual fixes for users adopting this new version.
Since Swift now automatically flattens optionals returned from throwing functions called with try?
, Unbox now uses throwing APIs for all unboxing methods. That means that while in previous versions, you’d unbox an optional property like this:
struct User: Unboxable {
var name: String?
init(unboxer: Unboxer) throws {
name = unboxer.unbox(key: "name")
}
}
You’ll now have to prefix such calls with try?
:
struct User: Unboxable {
var name: String?
init(unboxer: Unboxer) throws {
name = try? unboxer.unbox(key: "name")
}
}
While I realize that the above change brings a slight regression in terms of Unbox’s ease-of-use, it’s necessary in order to make Unbox support the latest Swift tools within a reasonable scope, and also moves Unbox's API to be more inline with modern Swift conventions for throwing methods.
View build details and download artifacts on buddybuild: Unbox (iOS, Unbox-iOS)
This version migrates Unbox to Swift 4.2.
View build details and download artifacts on buddybuild: Unbox (iOS, Unbox-iOS)
This version migrates Unbox to Swift 4.1
View build details and download artifacts on buddybuild: Unbox (iOS, Unbox-iOS)
This version of Unbox adds support for Xcode 9 and Swift 3.2, as well as re-organizes the project to be easier to browse, with separate files for each part of the API. It also enables the tests to be run using the Swift Package Manager.
unbox()
function. Works with both Data
and UnboxableDictionary
. Implemented by @mislavjavor.Decimal
is now a first-class number type, and gets automatically converted from other number types and strings. Implemented by @bencallis.Set
directly from an array, without any custom transformation code. Implemented by @hartbit.More unbox()
functions that return an Array
can now (optionally) be passed the allowInvalidElements
parameter.
UnboxPathError
is now public, meaning that the detailed error reporting introduced in 2.2
has now been combined with the granularity of earlier versions. UnboxError
is again an enum to enable developers to switch
on the different cases.8.1
. No more ⚠️.Data
to an array, you can now start unboxing at a certain key path.Unbox.swift
directly into a project, instead of using it as a library.This release makes Unbox usable with the new version of the Swift Package Manager.
This version is focused on increasing Unbox's speed - it's now up to 50% faster compared to the previous version! It also contains error reporting improvements.
Perfrormance
The next releases of Unbox will continue to make performance improvements in order to make decoding your JSON even more... eh... swift ?
Error reporting
Unbox now produces a coherent, easy to read error type. UnboxError
has been made into a struct instead of an enum, and when printed - it produces easily debuggable information.
For example, here's how an invalid array element would be reported in Unbox 2.1 or earlier:
[UnboxError] Invalid value ([1, "Bad value", 3]) for key "array"
And here's how Unbox 2.2 reports the same error:
[UnboxError] An error occured while unboxing path "model.array": Invalid array element ("Bad value") at index 1.
This also means you only have to catch one error type (UnboxError
) instead of performing complex pattern matching.
Decimal
can now be unboxed directly (thanks @garnett!)