From be695c448369e0c1064cccfbfee4b7a57134846f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Tue, 26 Nov 2024 21:16:15 +0100 Subject: [PATCH] Replace 'nonisolated(unsafe)' from Swift 5.10+ with a more compatible approach --- Sources/TelemetryDeck/TelemetryClient.swift | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Sources/TelemetryDeck/TelemetryClient.swift b/Sources/TelemetryDeck/TelemetryClient.swift index 708f58b..f31e7d4 100644 --- a/Sources/TelemetryDeck/TelemetryClient.swift +++ b/Sources/TelemetryDeck/TelemetryClient.swift @@ -325,8 +325,21 @@ public final class TelemetryManager: @unchecked Sendable { self.startSessionAndObserveAppForegrounding() } - nonisolated(unsafe) - static var initializedTelemetryManager: TelemetryManager? + private final class TelemetryManagerStorage: @unchecked Sendable { + static let shared = TelemetryManagerStorage() + private let queue = DispatchQueue(label: "com.telemetrydeck.TelemetryManager.static", attributes: .concurrent) + private var _manager: TelemetryManager? + + var manager: TelemetryManager? { + get { queue.sync { _manager } } + set { queue.sync(flags: .barrier) { _manager = newValue } } + } + } + + static var initializedTelemetryManager: TelemetryManager? { + get { TelemetryManagerStorage.shared.manager } + set { TelemetryManagerStorage.shared.manager = newValue } + } let signalManager: SignalManageable