From 747eec43bb56c2cb5d28863fbf1cb2f648f6390c Mon Sep 17 00:00:00 2001 From: Matt <85322+mattmassicotte@users.noreply.github.com> Date: Wed, 27 Mar 2024 07:03:11 -0400 Subject: [PATCH] Strict concurrency checking --- Package.swift | 12 +++++++++++- Sources/NSUI/ViewRepresentable.swift | 8 ++++++++ Tests/NSUITests/ControllerTests.swift | 1 + Tests/NSUITests/TextViewTests.swift | 2 ++ Tests/NSUITests/ViewRepresentableTests.swift | 1 + 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 7e1dba2..9c1203c 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.6 +// swift-tools-version: 5.8 import PackageDescription @@ -20,3 +20,13 @@ let package = Package( .testTarget(name: "NSUITests", dependencies: ["NSUI"]), ] ) + +let swiftSettings: [SwiftSetting] = [ + .enableExperimentalFeature("StrictConcurrency"), +] + +for target in package.targets { + var settings = target.swiftSettings ?? [] + settings.append(contentsOf: swiftSettings) + target.swiftSettings = settings +} diff --git a/Sources/NSUI/ViewRepresentable.swift b/Sources/NSUI/ViewRepresentable.swift index ae1138d..d5c482a 100644 --- a/Sources/NSUI/ViewRepresentable.swift +++ b/Sources/NSUI/ViewRepresentable.swift @@ -6,15 +6,19 @@ import AppKit public protocol NSUIViewRepresentable: NSViewRepresentable { associatedtype NSUIViewType: NSView + @MainActor func makeNSUIView(context: Context) -> NSUIViewType + @MainActor func updateNSUIView(_ view: NSUIViewType, context: Context) } public extension NSUIViewRepresentable { + @MainActor func makeNSView(context: Context) -> NSUIViewType { makeNSUIView(context: context) } + @MainActor func updateNSView(_ view: NSUIViewType, context: Context) { updateNSUIView(view, context: context) } @@ -26,15 +30,19 @@ import UIKit public protocol NSUIViewRepresentable: UIViewRepresentable { associatedtype NSUIViewType: UIView + @MainActor func makeNSUIView(context: Context) -> NSUIViewType + @MainActor func updateNSUIView(_ view: NSUIViewType, context: Context) } public extension NSUIViewRepresentable { + @MainActor func makeUIView(context: Context) -> NSUIViewType { makeNSUIView(context: context) } + @MainActor func updateUIView(_ view: NSUIViewType, context: Context) { updateNSUIView(view, context: context) } diff --git a/Tests/NSUITests/ControllerTests.swift b/Tests/NSUITests/ControllerTests.swift index c6a1a83..a2962c9 100644 --- a/Tests/NSUITests/ControllerTests.swift +++ b/Tests/NSUITests/ControllerTests.swift @@ -5,6 +5,7 @@ final class MyController: NSUIViewController { } final class ControllerTests: XCTestCase { + @MainActor func testControllerClassDefinition() throws { let _ = MyController() } diff --git a/Tests/NSUITests/TextViewTests.swift b/Tests/NSUITests/TextViewTests.swift index 47384b3..323a57f 100644 --- a/Tests/NSUITests/TextViewTests.swift +++ b/Tests/NSUITests/TextViewTests.swift @@ -2,6 +2,7 @@ import XCTest @testable import NSUI final class TextViewTests: XCTestCase { + @MainActor func testTextViewText() throws { let textView = NSUITextView() @@ -10,6 +11,7 @@ final class TextViewTests: XCTestCase { XCTAssertEqual(textView.text, "abc") } + @MainActor func testEditActions() throws { let edit = NSUITextStorageEditActions.editedAttributes diff --git a/Tests/NSUITests/ViewRepresentableTests.swift b/Tests/NSUITests/ViewRepresentableTests.swift index f5a9b82..397e9a2 100644 --- a/Tests/NSUITests/ViewRepresentableTests.swift +++ b/Tests/NSUITests/ViewRepresentableTests.swift @@ -1,6 +1,7 @@ import XCTest @testable import NSUI +@MainActor struct RepresentedView: NSUIViewRepresentable { typealias NSUIViewType = NSUIView