tl;dr How do I ensure my a property wrapper's init()
is called when wrapped by another property wrapper, and how do I get to keep those values when decoding?
struct Cow: Decodable {
@Rules(deletion: .cascade) var field1: Field
@Wrapper @Rules(deletion: .nullify) var field2: Field
}
When I decode this the following calls occur:
- Rules<Field>.init(deletion: .cascade)
- Wrapper<Rules<Field>>.init()
> Cow.init(from:)
> Rules<Field>.init(from:)
- Field.init(from:)
< Rules<Field>.init(from:)
- Rules<Field>.deinit
> Wrapper<Rules<Field>>.init(from:)
> Rules<Field>.init(from:)
- Field.init(from:)
< Rules<Field>.init(from:)
< Wrapper<Rules<Field>>.init(from:)
- Wrapper<Rules<Field>>.deinit
< Cow.init(from:)
Two problems occur:
-
Rules<Field>.init(deletion: .cascade)
is overwritten but the laterRules<Field>.init(from:)
-
Rules<Field>.init(deletion: .nullify)
is not called at all.
I can see why the overwrite happens, but very much wish to avoid. The non-call is just plain weird.