This must be hand crafted in SwiftUI because I have the opposite problem with the generated Decodable.init(from:)
: Property wrapper initialisation issues.
In the following example it's impossible (but I really hope I'm wrong) to access the 10
due to the way the compiler generates the initializer. Wrapper(importantValue: 10)
is called before Cow(from:)
but it's then entirely thrown away.
struct Cow: Codable {
@Wrapper(importantValue: 10) var legs: UInt
// This is generated by the compiler
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self._legs = try container.decode(Wrapper<UInt>.self, forKey: .legs)
}
}