From 5a37c3ffacfec494febc2700c381ef08a2a97862 Mon Sep 17 00:00:00 2001 From: Florian Friedrich Date: Tue, 12 Mar 2024 13:24:27 +0100 Subject: [PATCH] Fix build --- Sources/DeviceInformation/DeviceInfo.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Sources/DeviceInformation/DeviceInfo.swift b/Sources/DeviceInformation/DeviceInfo.swift index 38d277d..9092148 100644 --- a/Sources/DeviceInformation/DeviceInfo.swift +++ b/Sources/DeviceInformation/DeviceInfo.swift @@ -22,7 +22,22 @@ public struct DeviceInfo: Sendable, Equatable, Identifiable { #if canImport(WatchKit) // os(watchOS) return WKInterfaceDevice.current().systemName #elseif canImport(UIKit) && !targetEnvironment(macCatalyst) // os(iOS) os(tvOS) os(visionOS) - return UIDevice.current.systemName + @MainActor + func _access() -> String { UIDevice.current.systemName } + func _assumeIsolated(_ work: @MainActor () -> T) -> T { + if #available(iOS 13, tvOS 13, *) { + return MainActor.assumeIsolated(work) + } else { + return withoutActuallyEscaping(work) { + unsafeBitCast($0, to: (() -> T).self)() + } + } + } + if Thread.isMainThread { + return _assumeIsolated(_access) + } else { + return DispatchQueue.main.sync { _assumeIsolated(_access) } + } #elseif os(macOS) || targetEnvironment(macCatalyst) return "macOS" #elseif os(Linux)