Repository navigation
Unbox 2.0
Unbox 2.0 brings a new, streamlined API and reworked internals for maximum flexibility & performance.
swift2 branch.
All APIs have been reworked to follow the Swift 3 API naming guidelines
Unbox(_)is nowunbox(dictionary:),unbox(data:)andunbox(dictionaries:).UnboxableWithContext.ContextTypeis nowUnboxContext.UnboxableByTransform.UnboxRawValueTypeis nowUnboxRawValue.- Wherever key paths were supported with the
isKeyPath:argument, that has now been replaced withkey:andkeyPath:overloads. For exampleunboxer.unbox("company.title", isKeyPath: true)is nowunboxer.unbox(keyPath: "company.title"). - The
UnboxErrorenum now uses non-captailized first letters for its cases. UnboxableKey.transformUnboxedKey()is nowtransform(unboxedKey:).UnboxableByTransform.transformUnboxedValue()is nowtransform(unboxedValue:).UnboxFormatter.formatUnboxedValue()is nowformat(unboxedValue:).Unboxer.performCustomUnboxingWithDictionary()is nowperformCustomUnboxing(dictionary:)Unboxer.performCustomUnboxingWithArray()is nowperformCustomUnboxing(array:)Unboxer.performCustomUnboxingWithData()is nowperformCustomUnboxing(data:)
Swift native error handling model
Unboxable and UnboxableWithContext types can now throw from their initializer. This enables you to easily manually exit from an initializer, without having to use any specific APIs on Unboxer.
This new capability is also used when performing unboxing of values. Now, all required properties are unboxed using try, meaning that as soon as an error as been encountered, the initializer will be exited. This gives us a huge performance boost when dealing with malformed data, or when allowing invalid elements.
It also means that the unboxFallbackValue() function has been removed, and is no longer required to be implemented by types.
Finally, since now only one error can be thrown from an unboxing process (since we exit early) - UnboxError and UnboxValueError have been merged, and there's no longer a hasFailed property on Unboxer.
Any combination of arrays & dictionaries are now directly unboxable
Previously, Unbox only supported combinations of types and collections that were defined as overloads on Unboxer. Now, thanks to a reworked value resolving system, any combination of types and collections are supported. You can now directly unbox even the most complex data structures with one simple call to unbox().
Removals
Some APIs that have been kept around for legacy reasons have been removed in this release.
- You can no longer send a
contextwhen starting the unboxing process forUnboxabletypes. Instead, useUnboxableWithContext, which gives you strong typing for your contextual object. UnboxableWithFormatterhas been removed, since it wasn't needed. Formatting is still 100% supported, through the use of theUnboxFormatterAPI.