Firstly, I apologize for my poor English. I hope the content remains understandable.
GraphCodable is a Swift encode/decode package (similar to Codable at interface level) that does not treat reference types as second-class citizens.
With version 0.3.0 and later versions, the package has been completely revised. It now relies on
_mangledTypeName(...) (when available) and
NSStringFromClass(...) to generate the "type name" and on
NSClassFromString(...) to retrieve the class type from it.
With version 0.4.0 and later versions, GraphCodable supports identity for archiviving value types, to avoid duplication of their data.
Check code examples in the User Guide. Check the tests section, too.
(*) Full type checking at compile time is mutually exclusive with the ability to encode/decode heterogeneous collections (i.e.
[Any]) containing 'codable' elements. I chose to support the first feature while giving up the second.
Most Swift Standard Library and Foundation types are supported now. The list is here.
GraphCodable can encode and decode any Swift object graph, regardless of how complex it is, reconstructing its original structure with its original types without duplicating objects.
If the reference types form an acyclic graph, only
decode should be used in the
init (from: GDecoder) method.
If the reference types form a cyclic graph,
deferDecode must be used in the
init (from: GDecoder) method to "break" the cycle.
GraphCodable does not use a public format for the data (such as JSON or others) but stores the data in a private binary format defined by the package itself. Having to preserve information about the types, GraphCodable creates larger data in bytes than those generated by Codable encoders. Despite this, the time required for encoding and decoding is generally comparable if not faster.
GraphCodable is written entirely in Swift. The use of 'unsafe' methods is limited to a handful of functions related to reading and writing data in binary format (see BinaryIO). Everything else is 'safe'.
For now, the data format may be subject to future changes.
GraphCodable does not use containers.
Check it here.
GraphCodable is released under the MIT license. See LICENSE for more details.