From 8e3baa110790bb3db818d271cb8f0274cf427482 Mon Sep 17 00:00:00 2001 From: Leif Date: Thu, 21 Jul 2022 19:41:22 -0600 Subject: [PATCH] Update equating CacheStores --- .../Stores/CacheStore/CacheStore.swift | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Sources/CacheStore/Stores/CacheStore/CacheStore.swift b/Sources/CacheStore/Stores/CacheStore/CacheStore.swift index 55a70e7..bbfd6b1 100644 --- a/Sources/CacheStore/Stores/CacheStore/CacheStore.swift +++ b/Sources/CacheStore/Stores/CacheStore/CacheStore.swift @@ -218,8 +218,23 @@ extension CacheStore { guard cacheStoreCount == updatedStore.cache.count else { return false } - return updatedStore.cache.map { key, value in - isValueEqual(toUpdatedValue: value, forKey: key) + return updatedStore.cache.map { key, value -> Bool in + let mirror = Mirror(reflecting: value) + + if mirror.displayStyle != .optional { + return isValueEqual(toUpdatedValue: value, forKey: key) + } + + if mirror.children.isEmpty { + return (try? require(key)) == nil + } + + guard + let (_, unwrappedValue) = mirror.children.first + else { return (try? require(key)) == nil } + + return isValueEqual(toUpdatedValue: unwrappedValue, forKey: key) + } .reduce(into: true) { result, condition in guard condition else {