check for property via selector before using value(forKey:)

This commit is contained in:
Ilya Puchka
2018-09-11 18:12:27 +01:00
parent d71fe2a2ee
commit 0074ee1d4a
3 changed files with 12 additions and 2 deletions

View File

@@ -4,7 +4,9 @@
### Bug Fixes
_None_
- Now accessing undefined keys in NSObject does not cause runtime crash and instead renders empty string.
[Ilya Puchka](https://github.com/ilyapuchka)
[#234](https://github.com/stencilproject/Stencil/pull/234)
### Breaking Changes

View File

@@ -104,7 +104,9 @@ public struct Variable : Equatable, Resolvable {
#if os(Linux)
return nil
#else
if object.responds(to: Selector(bit)) {
current = object.value(forKey: bit)
}
#endif
} else if let value = current {
current = Mirror(reflecting: value).getValue(for: bit)

View File

@@ -148,6 +148,12 @@ func testVariable() {
let result = try variable.resolve(context) as? String
try expect(result) == "Foo"
}
$0.it("does not crash on KVO") {
let variable = Variable("object.fullname")
let result = try variable.resolve(context) as? String
try expect(result).to.beNil()
}
#endif
$0.it("can resolve a value via reflection") {