Skip to content

Commit dacc399

Browse files
authored
Fix a few sendability warnings in core. (pointfreeco#159)
1 parent 7ab04c6 commit dacc399

File tree

5 files changed

+79
-7
lines changed

5 files changed

+79
-7
lines changed

[email protected]

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// swift-tools-version:5.9
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "swiftui-navigation",
7+
platforms: [
8+
.iOS(.v13),
9+
.macOS(.v10_15),
10+
.tvOS(.v13),
11+
.watchOS(.v6),
12+
],
13+
products: [
14+
.library(
15+
name: "SwiftUINavigation",
16+
targets: ["SwiftUINavigation"]
17+
),
18+
.library(
19+
name: "SwiftUINavigationCore",
20+
targets: ["SwiftUINavigationCore"]
21+
),
22+
],
23+
dependencies: [
24+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
25+
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.2.2"),
26+
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.0.0"),
27+
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"),
28+
],
29+
targets: [
30+
.target(
31+
name: "SwiftUINavigation",
32+
dependencies: [
33+
"SwiftUINavigationCore",
34+
.product(name: "CasePaths", package: "swift-case-paths"),
35+
]
36+
),
37+
.testTarget(
38+
name: "SwiftUINavigationTests",
39+
dependencies: [
40+
"SwiftUINavigation"
41+
]
42+
),
43+
.target(
44+
name: "SwiftUINavigationCore",
45+
dependencies: [
46+
.product(name: "CustomDump", package: "swift-custom-dump"),
47+
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
48+
]
49+
),
50+
]
51+
)
52+
53+
for target in package.targets {
54+
target.swiftSettings = target.swiftSettings ?? []
55+
target.swiftSettings!.append(contentsOf: [
56+
.enableExperimentalFeature("StrictConcurrency")
57+
])
58+
// target.swiftSettings?.append(
59+
// .unsafeFlags([
60+
// "-enable-library-evolution",
61+
// ])
62+
// )
63+
}

Sources/SwiftUINavigation/Alert.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
/// dismisses the alert, and the action is fed to the `action` closure.
4747
/// - handler: A closure that is called with an action from a particular alert button when
4848
/// tapped.
49-
public func alert<Value>(
49+
public func alert<Value: Sendable>(
5050
_ state: Binding<AlertState<Value>?>,
51-
action handler: @escaping (Value?) async -> Void = { (_: Never?) async in }
51+
action handler: @escaping @Sendable (Value?) async -> Void = { (_: Never?) async in }
5252
) -> some View {
5353
alert(item: state) {
5454
Text($0.title)

Sources/SwiftUINavigation/ConfirmationDialog.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
/// - handler: A closure that is called with an action from a particular dialog button when
5050
/// tapped.
5151
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *)
52-
public func confirmationDialog<Value>(
52+
public func confirmationDialog<Value: Sendable>(
5353
_ state: Binding<ConfirmationDialogState<Value>?>,
54-
action handler: @escaping (Value?) async -> Void = { (_: Never?) async in }
54+
action handler: @escaping @Sendable (Value?) async -> Void = { (_: Never?) async in }
5555
) -> some View {
5656
confirmationDialog(
5757
item: state,

Sources/SwiftUINavigationCore/AlertState.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@
249249
/// - state: Alert state used to populate the alert.
250250
/// - action: An action handler, called when a button with an action is tapped, by passing the
251251
/// action to the closure.
252-
public init<Action>(_ state: AlertState<Action>, action: @escaping (Action?) async -> Void) {
252+
public init<Action: Sendable>(
253+
_ state: AlertState<Action>,
254+
action: @escaping @Sendable (Action?) async -> Void
255+
) {
253256
if state.buttons.count == 2 {
254257
self.init(
255258
title: Text(state.title),

Sources/SwiftUINavigationCore/ButtonState.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@
260260
/// - Parameters:
261261
/// - button: Button state.
262262
/// - action: An action closure that is invoked when the button is tapped.
263-
public init<Action>(_ button: ButtonState<Action>, action: @escaping (Action?) async -> Void) {
263+
public init<Action: Sendable>(
264+
_ button: ButtonState<Action>,
265+
action: @escaping @Sendable (Action?) async -> Void
266+
) {
264267
let action = { _ = Task { await button.withAction(action) } }
265268
switch button.role {
266269
case .cancel:
@@ -310,7 +313,10 @@
310313
/// - button: Button state.
311314
/// - action: An action closure that is invoked when the button is tapped.
312315
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *)
313-
public init<Action>(_ button: ButtonState<Action>, action: @escaping (Action?) async -> Void) {
316+
public init<Action: Sendable>(
317+
_ button: ButtonState<Action>,
318+
action: @escaping @Sendable (Action?) async -> Void
319+
) {
314320
self.init(
315321
role: button.role.map(ButtonRole.init),
316322
action: { Task { await button.withAction(action) } }

0 commit comments

Comments
 (0)