SuperCodable
From Foundation
To SuperCodable
Even random backend type
Can be found in Tests/SuperCodableTests/AnyValueDecode.swift
Feature
- Working with Nested
Foundation.Codable
property
Known side effect
- SuperDecoable must construct from nothing
init()
@Keyed var id:Int
will do O(n) calculation on underlaying wrapper_VARIABLE_NAME
into keyVARIABLE_NAME
. Be ware of variable name takes too long
Known Disability
- Every property in a SuperCodable should a
DecodableKey
/EncodableKey
, otherwise the property(which should beCodable
) will simply ignored during the Codable process.
Why:
Basically Mirror can't mutating the object value during the
init(from decoder:) throws
, since we create the object fromself.init()
Other notes
-
Inspired by: https://medium.com/trueid-developers/combined-propertywrapper-with-codable-swift-368dc4aa2703
-
Try to merge
@KeyedTransform
into@Keyed
, but it required@Keyed var id: String
to be@Keyed() var id: String
, with extra()
? -
Swift should auto generate
STRUCT.init(....)
for you, but if you using@Keyed var id: String
without default value, it will generateinit(id: Keyed<String>)
, by giving default value@Keyed var id: String = ""
should solve this problem.
Know Issues
@Keyed var id:String?
will cause fatalError on force unwrappingKeyed.value?
, you can using@OptionalKeyed
to make it works.OptionalKeyed
may / may not a good name, I am thinking of make the easy to change, maybeKeyedOptional
is EASY change? ?