Swift 4个新的KVC
Swift 4 new KVC
我正在尝试了解 Swift 4 - better KVC 的最新补充。在 playground 中使用这些简单的东西不会打印出任何内容
class Foo {
var name: String
init(name: String) {
self.name = name
}
}
class Bar {
var fooObject: Foo = Foo(name: "FooName")
var keyPath = \Foo.name
func output() {
print(fooObject[keyPath: keyPath])
}
}
let bar = Bar()
bar.output()
尽管如此,如果您稍作更改并尝试输出以下内容,它就会起作用:
print(fooObject[keyPath: \Foo.name])
谁能解释一下?它仍然是越野车还是我只是在这里做一些愚蠢的事情?谢谢
您需要更新到 Xcode 9 beta 4,它已修复。
我正在尝试了解 Swift 4 - better KVC 的最新补充。在 playground 中使用这些简单的东西不会打印出任何内容
class Foo {
var name: String
init(name: String) {
self.name = name
}
}
class Bar {
var fooObject: Foo = Foo(name: "FooName")
var keyPath = \Foo.name
func output() {
print(fooObject[keyPath: keyPath])
}
}
let bar = Bar()
bar.output()
尽管如此,如果您稍作更改并尝试输出以下内容,它就会起作用:
print(fooObject[keyPath: \Foo.name])
谁能解释一下?它仍然是越野车还是我只是在这里做一些愚蠢的事情?谢谢
您需要更新到 Xcode 9 beta 4,它已修复。