示例工程 17-reflection-keypaths

17-reflection-keypaths/Diagnostics/KeyPathTypeMismatch.swift

swift · 0.2 KB

// 故意编译失败:KeyPath 的类型决定可赋值的值类型。
// 复现:swiftc Diagnostics/KeyPathTypeMismatch.swift
struct Point {
    var x = 0
}
 
var point = Point()
point[keyPath: \.x] = "one"
print(point.x)