Viktor Kucera Viktor Kucera - 3 years ago 162
Swift Question

Swift 4 new KVC

I am trying to understand latest addition to Swift 4 - better KVC. Having this simple stuff in playground prints out nothing

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()


Although, it works if you make a small change and try to output this:

print(fooObject[keyPath: \Foo.name])


Can someone explain? Is it still buggy or am I just doing something stupid here? Thanks.

Answer Source

Works fine under Xcode 9 beta 4. Looks like fixed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download