Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法从 Swift 4 中的字符串创建 Keypath 以通过其路径或变量名访问结构中的值
最后我发现我应该使用 CodingKeys 而不是 KeyPaths 来通过 String 访问结构的变量的值
在此先感谢,迈克尔
考虑你有这样的东西,
struct foo { var test: doo } struct doo { var test: Int } //How to use it let doo = Doo(test: 10) let foo = Foo(test: doo) let mykeyPath = \Foo.test.test let result = foo[keyPath: mykeyPath] print(result)