From a1507705d156316fa1a06b71d42e43bef9d0c2d9 Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Wed, 4 Dec 2024 16:33:49 +0100 Subject: [PATCH] Use actor isolation for `SubscriptionFeatureMappingCache` (#1113) **Required**: Task/Issue URL: https://app.asana.com/0/414709148257752/1208887772407026/f iOS PR: https://github.com/duckduckgo/iOS/pull/3670 macOS PR: What kind of version bump will this require?: Hotfix **Description**: Use actor isolation for `SubscriptionFeatureMappingCache` --- ###### Internal references: [Software Engineering Expectations](https://app.asana.com/0/59792373528535/199064865822552) [Technical Design Template](https://app.asana.com/0/59792373528535/184709971311943) --- Sources/Subscription/SubscriptionFeatureMappingCache.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Sources/Subscription/SubscriptionFeatureMappingCache.swift b/Sources/Subscription/SubscriptionFeatureMappingCache.swift index 414fec1d7..9bfa3cee1 100644 --- a/Sources/Subscription/SubscriptionFeatureMappingCache.swift +++ b/Sources/Subscription/SubscriptionFeatureMappingCache.swift @@ -23,13 +23,11 @@ public protocol SubscriptionFeatureMappingCache { func subscriptionFeatures(for subscriptionIdentifier: String) async -> [Entitlement.ProductName] } -public final class DefaultSubscriptionFeatureMappingCache: SubscriptionFeatureMappingCache { +public actor DefaultSubscriptionFeatureMappingCache: SubscriptionFeatureMappingCache { private let subscriptionEndpointService: SubscriptionEndpointService private let userDefaults: UserDefaults - private var subscriptionFeatureMapping: SubscriptionFeatureMapping? - public init(subscriptionEndpointService: SubscriptionEndpointService, userDefaults: UserDefaults) { self.subscriptionEndpointService = subscriptionEndpointService self.userDefaults = userDefaults @@ -96,7 +94,7 @@ public final class DefaultSubscriptionFeatureMappingCache: SubscriptionFeatureMa static private let subscriptionFeatureMappingKey = "com.duckduckgo.subscription.featuremapping" - dynamic var storedFeatureMapping: SubscriptionFeatureMapping? { + var storedFeatureMapping: SubscriptionFeatureMapping? { get { guard let data = userDefaults.data(forKey: Self.subscriptionFeatureMappingKey) else { return nil } do {