From 644687b885eb8a012dc113d79e39e561f1a0fd13 Mon Sep 17 00:00:00 2001 From: Ruslan Alikhamov Date: Sun, 20 Aug 2023 10:28:27 +0000 Subject: [PATCH 1/5] prefer DynamicMemberLookup over KVC --- Sources/Stencil/Variable.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Stencil/Variable.swift b/Sources/Stencil/Variable.swift index 1948f4e3..708fbe08 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) + #if canImport(ObjectiveC) return nil #else if object.responds(to: Selector(bit)) { return object.value(forKey: bit) } #endif - } else if let value = context as? DynamicMemberLookup { - return value[dynamicMember: bit] } else if let value = context { return Mirror(reflecting: value).getValue(for: bit) } From 973609e141dcc89ecabe205e35bb3dfb3a8e2e65 Mon Sep 17 00:00:00 2001 From: Ruslan Alikhamov Date: Sun, 20 Aug 2023 15:05:35 +0400 Subject: [PATCH 2/5] Update Variable.swift - Fixed a typo for objc runtime check --- Sources/Stencil/Variable.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Stencil/Variable.swift b/Sources/Stencil/Variable.swift index 708fbe08..f12c0dbe 100644 --- a/Sources/Stencil/Variable.swift +++ b/Sources/Stencil/Variable.swift @@ -113,7 +113,7 @@ public struct Variable: Equatable, Resolvable { } else if let value = context as? DynamicMemberLookup { return value[dynamicMember: bit] } else if let object = context as? NSObject { // NSKeyValueCoding - #if canImport(ObjectiveC) + #if !canImport(ObjectiveC) return nil #else if object.responds(to: Selector(bit)) { From 6b6d6c2730c37ea6eedd7d9b604a2aa05737ed24 Mon Sep 17 00:00:00 2001 From: Ruslan Alikhamov Date: Sat, 26 Aug 2023 01:03:49 -0400 Subject: [PATCH 3/5] changed order of condition to make positive case first --- Sources/Stencil/Variable.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Stencil/Variable.swift b/Sources/Stencil/Variable.swift index f12c0dbe..dc5b86e8 100644 --- a/Sources/Stencil/Variable.swift +++ b/Sources/Stencil/Variable.swift @@ -113,12 +113,12 @@ public struct Variable: Equatable, Resolvable { } else if let value = context as? DynamicMemberLookup { return value[dynamicMember: bit] } else if let object = context as? NSObject { // NSKeyValueCoding - #if !canImport(ObjectiveC) - 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 { return Mirror(reflecting: value).getValue(for: bit) From 930db330286a61a01829b5f0d9f501bd9fefa237 Mon Sep 17 00:00:00 2001 From: Ruslan Alikhamov Date: Sat, 26 Aug 2023 05:07:29 +0000 Subject: [PATCH 4/5] updated changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e0a2d27..31638e7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ - Fix bug in `LazyValueWrapper`, causing it to never resolve. [David Jennes](https://github.com/djbe) [#328](https://github.com/stencilproject/Stencil/pull/328) +- Prefer `DynamicMemberLookup` over KVC. + [##342](https://github.com/stencilproject/Stencil/pull/342) + [@art-divin](https://github.com/art-divin) ## 0.15.0 From ea58733eb66b063f37288d009959d47c09f520c7 Mon Sep 17 00:00:00 2001 From: Ruslan Alikhamov Date: Sat, 26 Aug 2023 05:10:17 +0000 Subject: [PATCH 5/5] added new version in CHANGELOG --- CHANGELOG.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31638e7f..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 @@ -5,9 +13,6 @@ - Fix bug in `LazyValueWrapper`, causing it to never resolve. [David Jennes](https://github.com/djbe) [#328](https://github.com/stencilproject/Stencil/pull/328) -- Prefer `DynamicMemberLookup` over KVC. - [##342](https://github.com/stencilproject/Stencil/pull/342) - [@art-divin](https://github.com/art-divin) ## 0.15.0