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) { = name

class Bar {

var fooObject: Foo = Foo(name: "FooName")
var keyPath = \

func output() {
print(fooObject[keyPath: keyPath])

let bar = Bar()

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

print(fooObject[keyPath: \])

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