Skip to content

Commit d32aa2f

Browse files
committed
@mainactor defaultScale
1 parent 24060d3 commit d32aa2f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

SwiftDraw/UIImage+SVG.swift

Lines changed: 19 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,20 @@ extension SVG {
140141
}
141142

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

SwiftDrawTests/Renderer.CoreGraphicsTypesTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ final class RendererCoreGraphicsTypesTests: XCTestCase {
109109
let segments: [CGPath.Segment] = [.move(CGPoint(0, 0)), .line(CGPoint(10, 20)), .line(CGPoint(30, 40))]
110110
XCTAssertEqual(path.segments(), segments)
111111
}
112-
112+
113+
@MainActor
113114
func testShapeRect() {
114115
let path = CGProvider().createPath(from: .rect(within: Rect(x: 10, y: 20, width: 30, height: 40),
115116
radii: Size(2, 4)))

0 commit comments

Comments
 (0)