That's the cost, yeah. It might be possible to solve this with nested property wrappers; a quick simplified attempt seems to work.
(code)
import SwiftUI
@propertyWrapper
struct Wrap {
var wrappedValue: Int
}
extension Wrap: RawRepresentable {
var rawValue: String {
wrappedValue.description
}
init?(rawValue: String) {
guard let value = Int(rawValue) else {
return nil
}
wrappedValue = value
}
}
struct Test {
@AppStorage("x") @Wrap var x: Int = 5
}
Test().x = 6
print(UserDefaults.standard.object(forKey: "x"))
I meant "…SinceReferenceDate" but once again the fact that it's ambiguous sort of points out why you shouldn't do this: someone else might have different opinions.