diff --git a/Airship/AirshipCore/Source/ChannelAudienceManager.swift b/Airship/AirshipCore/Source/ChannelAudienceManager.swift index c10226271..01582ef38 100644 --- a/Airship/AirshipCore/Source/ChannelAudienceManager.swift +++ b/Airship/AirshipCore/Source/ChannelAudienceManager.swift @@ -45,8 +45,6 @@ final class ChannelAudienceManager: ChannelAudienceManagerProtocol { private let audienceOverridesProvider: AudienceOverridesProvider private let date: AirshipDateProtocol - private let encoder = JSONEncoder() - private let decoder = JSONDecoder() private let updateLock = AirshipLock() private let cachedSubscriptionLists: CachedValue<[String]> @@ -350,7 +348,7 @@ final class ChannelAudienceManager: ChannelAudienceManagerProtocol { if let data = self.dataStore.data( forKey: ChannelAudienceManager.updatesKey ) { - result = try? self.decoder.decode( + result = try? JSONDecoder().decode( [AudienceUpdate].self, from: data ) @@ -361,7 +359,7 @@ final class ChannelAudienceManager: ChannelAudienceManagerProtocol { private func storeUpdates(_ operations: [AudienceUpdate]) { updateLock.sync { - if let data = try? self.encoder.encode(operations) { + if let data = try? JSONEncoder().encode(operations) { self.dataStore.setObject( data, forKey: ChannelAudienceManager.updatesKey diff --git a/Airship/AirshipCore/Source/ChannelAuthTokenAPIClient.swift b/Airship/AirshipCore/Source/ChannelAuthTokenAPIClient.swift index 3987889d5..92e901890 100644 --- a/Airship/AirshipCore/Source/ChannelAuthTokenAPIClient.swift +++ b/Airship/AirshipCore/Source/ChannelAuthTokenAPIClient.swift @@ -4,7 +4,6 @@ final class ChannelAuthTokenAPIClient: ChannelAuthTokenAPIClientProtocol, Sendab private let tokenPath = "/api/auth/device" private let config: RuntimeConfig private let session: AirshipRequestSession - private let decoder: JSONDecoder = JSONDecoder() init( config: RuntimeConfig, diff --git a/Airship/AirshipCore/Source/ContactAPIClient.swift b/Airship/AirshipCore/Source/ContactAPIClient.swift index c62dc7e58..544b19cc9 100644 --- a/Airship/AirshipCore/Source/ContactAPIClient.swift +++ b/Airship/AirshipCore/Source/ContactAPIClient.swift @@ -72,7 +72,7 @@ final class ContactAPIClient: ContactsAPIClientProtocol { private let config: RuntimeConfig private let session: AirshipRequestSession - private let decoder: JSONDecoder = { + private var decoder: JSONDecoder { let decoder = JSONDecoder() decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in let container = try decoder.singleValueContainer() @@ -84,9 +84,9 @@ final class ContactAPIClient: ContactsAPIClientProtocol { return date }) return decoder - }() + } - private let encoder: JSONEncoder = { + private var encoder: JSONEncoder { let encoder = JSONEncoder() encoder.dateEncodingStrategy = .custom({ date, encoder in var container = encoder.singleValueContainer() @@ -95,7 +95,7 @@ final class ContactAPIClient: ContactsAPIClientProtocol { ) }) return encoder - }() + } init(config: RuntimeConfig, session: AirshipRequestSession) { self.config = config diff --git a/Airship/AirshipCore/Source/ContactChannelsAPIClient.swift b/Airship/AirshipCore/Source/ContactChannelsAPIClient.swift index d41625b4f..30534fec9 100644 --- a/Airship/AirshipCore/Source/ContactChannelsAPIClient.swift +++ b/Airship/AirshipCore/Source/ContactChannelsAPIClient.swift @@ -14,7 +14,7 @@ final class ContactChannelsAPIClient: ContactChannelsAPIClientProtocol { private let config: RuntimeConfig private let session: AirshipRequestSession - private let decoder: JSONDecoder = { + private var decoder: JSONDecoder { let decoder = JSONDecoder() decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in let container = try decoder.singleValueContainer() @@ -26,7 +26,7 @@ final class ContactChannelsAPIClient: ContactChannelsAPIClientProtocol { return date }) return decoder - }() + } init(config: RuntimeConfig, session: AirshipRequestSession) { self.config = config diff --git a/Airship/AirshipCore/Source/PreferenceDataStore.swift b/Airship/AirshipCore/Source/PreferenceDataStore.swift index bd735a74b..00510f197 100644 --- a/Airship/AirshipCore/Source/PreferenceDataStore.swift +++ b/Airship/AirshipCore/Source/PreferenceDataStore.swift @@ -8,9 +8,6 @@ public final class PreferenceDataStore: @unchecked Sendable { private let defaults: UserDefaults private let appKey: String static let deviceIDKey = "deviceID" - - private let decoder = JSONDecoder() - private let encoder = JSONEncoder() private var pending: [String: [Any?]] = [:] private var cache: [String: Cached] = [:] @@ -177,7 +174,7 @@ public final class PreferenceDataStore: @unchecked Sendable { return nil } - return try decoder.decode(T.self, from: data) + return try JSONDecoder().decode(T.self, from: data) } public func safeCodable(forKey key: String) -> T? { @@ -209,7 +206,7 @@ public final class PreferenceDataStore: @unchecked Sendable { return } - let data = try encoder.encode(codable) + let data = try JSONEncoder().encode(codable) write(key, value: data) } diff --git a/Airship/AirshipCore/Source/RemoteDataAPIClient.swift b/Airship/AirshipCore/Source/RemoteDataAPIClient.swift index 574e84037..700c6681b 100644 --- a/Airship/AirshipCore/Source/RemoteDataAPIClient.swift +++ b/Airship/AirshipCore/Source/RemoteDataAPIClient.swift @@ -13,7 +13,7 @@ final class RemoteDataAPIClient: RemoteDataAPIClientProtocol { private let session: AirshipRequestSession private let config: RuntimeConfig - private let decoder: JSONDecoder = { + private var decoder: JSONDecoder { let decoder = JSONDecoder() decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in let container = try decoder.singleValueContainer() @@ -25,7 +25,7 @@ final class RemoteDataAPIClient: RemoteDataAPIClientProtocol { return date }) return decoder - }() + } init(config: RuntimeConfig, session: AirshipRequestSession) { self.config = config diff --git a/Airship/AirshipCore/Source/RemoteDataInfo.swift b/Airship/AirshipCore/Source/RemoteDataInfo.swift index 492032d84..37dcdf8ee 100644 --- a/Airship/AirshipCore/Source/RemoteDataInfo.swift +++ b/Airship/AirshipCore/Source/RemoteDataInfo.swift @@ -14,14 +14,11 @@ public struct RemoteDataInfo: Sendable, Codable, Equatable, Hashable { self.contactID = contactID } - private static let decoder = JSONDecoder() - private static let encoder = JSONEncoder() - static func fromJSON(data: Data) throws -> RemoteDataInfo { - return try RemoteDataInfo.decoder.decode(RemoteDataInfo.self, from: data) + try JSONDecoder().decode(RemoteDataInfo.self, from: data) } func toEncodedJSONData() throws -> Data { - return try RemoteDataInfo.encoder.encode(self) + try JSONEncoder().encode(self) } } diff --git a/Airship/AirshipCore/Source/SMSValidator.swift b/Airship/AirshipCore/Source/SMSValidator.swift index def1931cc..a81e9b897 100644 --- a/Airship/AirshipCore/Source/SMSValidator.swift +++ b/Airship/AirshipCore/Source/SMSValidator.swift @@ -92,7 +92,7 @@ final class SMSValidatorAPIClient: SMSValidatorAPIClientProtocol { private let config: RuntimeConfig private let session: AirshipRequestSession - private let decoder: JSONDecoder = { + private var decoder: JSONDecoder { let decoder = JSONDecoder() decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in let container = try decoder.singleValueContainer() @@ -104,9 +104,9 @@ final class SMSValidatorAPIClient: SMSValidatorAPIClientProtocol { return date }) return decoder - }() + } - private let encoder: JSONEncoder = { + private var encoder: JSONEncoder { let encoder = JSONEncoder() encoder.dateEncodingStrategy = .custom({ date, encoder in var container = encoder.singleValueContainer() @@ -115,7 +115,7 @@ final class SMSValidatorAPIClient: SMSValidatorAPIClientProtocol { ) }) return encoder - }() + } init(config: RuntimeConfig, session: AirshipRequestSession) { self.config = config diff --git a/Airship/AirshipCore/Source/SubscriptionListAction.swift b/Airship/AirshipCore/Source/SubscriptionListAction.swift index f190ba1ca..571d14633 100644 --- a/Airship/AirshipCore/Source/SubscriptionListAction.swift +++ b/Airship/AirshipCore/Source/SubscriptionListAction.swift @@ -23,11 +23,11 @@ public final class SubscriptionListAction: AirshipAction { private let channel: @Sendable () -> AirshipChannelProtocol private let contact: @Sendable () -> AirshipContactProtocol - private let decoder: JSONDecoder = { + private var decoder: JSONDecoder { let decoder = JSONDecoder() decoder.dateDecodingStrategy = .iso8601 return decoder - }() + } public var _decoder: JSONDecoder { return decoder