Skip to content

Commit 72a0d5b

Browse files
committed
@mainactor defaultScale
1 parent 9681807 commit 72a0d5b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

SwiftDraw/UIImage+SVG.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// 3. This notice may not be removed or altered from any source distribution.
3030
//
3131

32+
import Foundation
3233
#if canImport(UIKit)
3334
import UIKit
3435
#if canImport(WatchKit)
@@ -126,7 +127,7 @@ extension SVG {
126127
#if os(watchOS)
127128
WKInterfaceDevice.current().screenScale
128129
#else
129-
UIScreen.main.scale
130+
MainActor.syncIsolated { UIScreen.main.scale }
130131
#endif
131132
}
132133

@@ -140,3 +141,14 @@ extension SVG {
140141
}
141142

142143
#endif
144+
145+
private extension MainActor {
146+
147+
static func syncIsolated<T: Sendable>(operation: @MainActor () -> T) -> T {
148+
if Thread.isMainThread {
149+
return MainActor.assumeIsolated { operation() }
150+
} else {
151+
return DispatchQueue.main.sync { operation() }
152+
}
153+
}
154+
}

0 commit comments

Comments
 (0)