Skip to content

Commit

Permalink
Fix a few sendability warnings in core. (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw authored May 28, 2024
1 parent 7ab04c6 commit dacc399
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
63 changes: 63 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// swift-tools-version:5.9

import PackageDescription

let package = Package(
name: "swiftui-navigation",
platforms: [
.iOS(.v13),
.macOS(.v10_15),
.tvOS(.v13),
.watchOS(.v6),
],
products: [
.library(
name: "SwiftUINavigation",
targets: ["SwiftUINavigation"]
),
.library(
name: "SwiftUINavigationCore",
targets: ["SwiftUINavigationCore"]
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.2.2"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"),
],
targets: [
.target(
name: "SwiftUINavigation",
dependencies: [
"SwiftUINavigationCore",
.product(name: "CasePaths", package: "swift-case-paths"),
]
),
.testTarget(
name: "SwiftUINavigationTests",
dependencies: [
"SwiftUINavigation"
]
),
.target(
name: "SwiftUINavigationCore",
dependencies: [
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
]
)

for target in package.targets {
target.swiftSettings = target.swiftSettings ?? []
target.swiftSettings!.append(contentsOf: [
.enableExperimentalFeature("StrictConcurrency")
])
// target.swiftSettings?.append(
// .unsafeFlags([
// "-enable-library-evolution",
// ])
// )
}
4 changes: 2 additions & 2 deletions Sources/SwiftUINavigation/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
/// dismisses the alert, and the action is fed to the `action` closure.
/// - handler: A closure that is called with an action from a particular alert button when
/// tapped.
public func alert<Value>(
public func alert<Value: Sendable>(
_ state: Binding<AlertState<Value>?>,
action handler: @escaping (Value?) async -> Void = { (_: Never?) async in }
action handler: @escaping @Sendable (Value?) async -> Void = { (_: Never?) async in }
) -> some View {
alert(item: state) {
Text($0.title)
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftUINavigation/ConfirmationDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
/// - handler: A closure that is called with an action from a particular dialog button when
/// tapped.
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *)
public func confirmationDialog<Value>(
public func confirmationDialog<Value: Sendable>(
_ state: Binding<ConfirmationDialogState<Value>?>,
action handler: @escaping (Value?) async -> Void = { (_: Never?) async in }
action handler: @escaping @Sendable (Value?) async -> Void = { (_: Never?) async in }
) -> some View {
confirmationDialog(
item: state,
Expand Down
5 changes: 4 additions & 1 deletion Sources/SwiftUINavigationCore/AlertState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@
/// - state: Alert state used to populate the alert.
/// - action: An action handler, called when a button with an action is tapped, by passing the
/// action to the closure.
public init<Action>(_ state: AlertState<Action>, action: @escaping (Action?) async -> Void) {
public init<Action: Sendable>(
_ state: AlertState<Action>,
action: @escaping @Sendable (Action?) async -> Void
) {
if state.buttons.count == 2 {
self.init(
title: Text(state.title),
Expand Down
10 changes: 8 additions & 2 deletions Sources/SwiftUINavigationCore/ButtonState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@
/// - Parameters:
/// - button: Button state.
/// - action: An action closure that is invoked when the button is tapped.
public init<Action>(_ button: ButtonState<Action>, action: @escaping (Action?) async -> Void) {
public init<Action: Sendable>(
_ button: ButtonState<Action>,
action: @escaping @Sendable (Action?) async -> Void
) {
let action = { _ = Task { await button.withAction(action) } }
switch button.role {
case .cancel:
Expand Down Expand Up @@ -310,7 +313,10 @@
/// - button: Button state.
/// - action: An action closure that is invoked when the button is tapped.
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *)
public init<Action>(_ button: ButtonState<Action>, action: @escaping (Action?) async -> Void) {
public init<Action: Sendable>(
_ button: ButtonState<Action>,
action: @escaping @Sendable (Action?) async -> Void
) {
self.init(
role: button.role.map(ButtonRole.init),
action: { Task { await button.withAction(action) } }
Expand Down

0 comments on commit dacc399

Please sign in to comment.