diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e0a2d27..f83e1a24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.15.2 + +### Enhancements + +- Prefer `DynamicMemberLookup` over KVC. + [##342](https://github.com/stencilproject/Stencil/pull/342) + [@art-divin](https://github.com/art-divin) + ## 0.15.1 ### Bug Fixes diff --git a/Sources/Stencil/Variable.swift b/Sources/Stencil/Variable.swift index 1948f4e3..dc5b86e8 100644 --- a/Sources/Stencil/Variable.swift +++ b/Sources/Stencil/Variable.swift @@ -110,16 +110,16 @@ public struct Variable: Equatable, Resolvable { return resolve(bit: bit, collection: array) } else if let string = context as? String { return resolve(bit: bit, collection: string) + } else if let value = context as? DynamicMemberLookup { + return value[dynamicMember: bit] } else if let object = context as? NSObject { // NSKeyValueCoding - #if os(Linux) - return nil - #else + #if canImport(ObjectiveC) if object.responds(to: Selector(bit)) { return object.value(forKey: bit) } + #else + return nil #endif - } else if let value = context as? DynamicMemberLookup { - return value[dynamicMember: bit] } else if let value = context { return Mirror(reflecting: value).getValue(for: bit) }