Let's examing following code:
@propertyWrapper
struct Argument {
var wrappedValue: Int?
var argument: String
}
struct Model {
@Argument var property: Int?
@Argument(argument: "bar") var foo: Int? = nil
}
extension Model {
init(property: Int, argument: String = "hello") {
_property = Argument(wrappedValue: property, argument: argument)
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let model = Model(property: 5)
print(model)
}
}
Output looks like this:
Model(_property: propertyWrapper.Argument(wrappedValue: Optional(5), argument: "hello"), _foo: propertyWrapper.Argument(wrappedValue: nil, argument: "bar"))
So the printing function somehow has access to a property wrapper argument.
However model.property
is just Int?, the same as model.foo
. How can I extract arguments like "hello" and "bar" like this?
print(model.property.argument) // prints "hello"
print(model.foo.argument) // prints "bar"
Is this possible?