Swift and KVC


Marco S Hyman
 

This simple little playground doesn’t print any value for the last line. It is a minimization of an issue I’m having in a larger program where the key-value can not be found. Is it me (likely) or is it swift and KVC?

Xcode 9.3

```
//: Playground - noun: a place where people can play

import Cocoa

var str = "Hello, playground"

class Foo: NSObject {
// ...
}

extension Foo {
var name: String {
return "foo name"
}
}

let foo = Foo()
print(foo.name) // prints “foo name"
let fooName = foo.value(forKey: "name")
print(fooName as! String) // prints nothing
```


Marc

Join cocoa@apple-dev.groups.io to automatically receive all group messages.