TIL @ attributes in Swift
Read chapter Attributes of Swift Reference. Good reference. Among others has useful example of using @dynamicMemberLookup
for implementing PassthroughWrapper
:
struct Point { var x, y: Int }
@dynamicMemberLookup
struct PassthroughWrapper<Value> {
var value: Value
subscript<T>(dynamicMember member: KeyPath<Value, T>) -> T {
get { return value[keyPath: member] }
}
}
let point = Point(x: 381, y: 431)
let wrapper = PassthroughWrapper(value: point)
print(wrapper.x)