Merge pull request #234 from stencilproject/check-kvo

Check for property via selector before using value(forKey:)
This commit is contained in:
David Jennes
2018-09-11 23:59:54 +02:00
committed by GitHub
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
current = object.value(forKey: bit)
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") {