Skip to content

Commit 780edcc

Browse files
jpsimmbrandonw
andauthored
Add Sendable conformances (pointfreeco#120)
* Add `Sendable` conformances SwiftUI only annotated some of the types that are used in this package with Xcode 15 / Swift 5.9, so we need to guard conformances only when compiling with Swift 5.9 or higher. Thanks @rowjo for starting this work in https://github.com/pointfreeco/swiftui-navigation/pull/116. * Small fixes. --------- Co-authored-by: Brandon Williams <[email protected]>
1 parent db922a3 commit 780edcc

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

Sources/SwiftUINavigationCore/ButtonState.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public struct ButtonStateAction<Action> {
147147
/// A value that describes the purpose of a button.
148148
///
149149
/// See `SwiftUI.ButtonRole` for more information.
150-
public enum ButtonStateRole {
150+
public enum ButtonStateRole: Sendable {
151151
/// A role that indicates a cancel button.
152152
///
153153
/// See `SwiftUI.ButtonRole.cancel` for more information.
@@ -227,6 +227,12 @@ extension ButtonState: Hashable where Action: Hashable {
227227
}
228228
}
229229

230+
#if swift(>=5.7)
231+
extension ButtonStateAction: Sendable where Action: Sendable {}
232+
extension ButtonStateAction._ActionType: Sendable where Action: Sendable {}
233+
extension ButtonState: Sendable where Action: Sendable {}
234+
#endif
235+
230236
// MARK: - SwiftUI bridging
231237

232238
extension Alert.Button {

Sources/SwiftUINavigationCore/ConfirmationDialogState.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public struct ConfirmationDialogState<Action>: Identifiable {
199199
/// platform, current context, and other factors.
200200
///
201201
/// See `SwiftUI.Visibility` for more information.
202-
public enum ConfirmationDialogStateTitleVisibility {
202+
public enum ConfirmationDialogStateTitleVisibility: Sendable {
203203
/// The element may be visible or hidden depending on the policies of the component accepting the
204204
/// visibility configuration.
205205
///
@@ -265,6 +265,14 @@ extension ConfirmationDialogState: Hashable where Action: Hashable {
265265
}
266266
}
267267

268+
#if swift(>=5.7)
269+
@available(iOS 13, *)
270+
@available(macOS 12, *)
271+
@available(tvOS 13, *)
272+
@available(watchOS 6, *)
273+
extension ConfirmationDialogState: Sendable where Action: Sendable {}
274+
#endif
275+
268276
// MARK: - SwiftUI bridging
269277

270278
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *)

Sources/SwiftUINavigationCore/TextState.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ import SwiftUI
4343
/// - Note: ``TextState`` does not support _all_ `LocalizedStringKey` permutations at this time
4444
/// (interpolated `SwiftUI.Image`s, for example). ``TextState`` also uses reflection to determine
4545
/// `LocalizedStringKey` equatability, so be mindful of edge cases.
46-
public struct TextState: Equatable, Hashable {
46+
public struct TextState: Equatable, Hashable, Sendable {
4747
fileprivate var modifiers: [Modifier] = []
4848
fileprivate let storage: Storage
4949

50-
fileprivate enum Modifier: Equatable, Hashable {
50+
fileprivate enum Modifier: Equatable, Hashable, Sendable {
5151
case accessibilityHeading(AccessibilityHeadingLevel)
5252
case accessibilityLabel(TextState)
5353
case accessibilityTextContentType(AccessibilityTextContentType)
@@ -70,7 +70,7 @@ public struct TextState: Equatable, Hashable {
7070
case underline(isActive: Bool, pattern: LineStylePattern?, color: Color?)
7171
}
7272

73-
public enum FontWidth: String, Equatable, Hashable {
73+
public enum FontWidth: String, Equatable, Hashable, Sendable {
7474
case compressed
7575
case condensed
7676
case expanded
@@ -89,7 +89,7 @@ public struct TextState: Equatable, Hashable {
8989
#endif
9090
}
9191

92-
public enum LineStylePattern: String, Equatable, Hashable {
92+
public enum LineStylePattern: String, Equatable, Hashable, Sendable {
9393
case dash
9494
case dashDot
9595
case dashDotDot
@@ -108,7 +108,9 @@ public struct TextState: Equatable, Hashable {
108108
}
109109
}
110110

111-
fileprivate enum Storage: Equatable, Hashable {
111+
// NB: LocalizedStringKey is documented as being Sendable, but its conformance appears to be
112+
// unavailable.
113+
fileprivate enum Storage: Equatable, Hashable, @unchecked Sendable {
112114
indirect case concatenated(TextState, TextState)
113115
case localized(LocalizedStringKey, tableName: String?, bundle: Bundle?, comment: StaticString?)
114116
case verbatim(String)
@@ -305,7 +307,7 @@ extension TextState {
305307
// MARK: Accessibility
306308

307309
extension TextState {
308-
public enum AccessibilityTextContentType: String, Equatable, Hashable {
310+
public enum AccessibilityTextContentType: String, Equatable, Hashable, Sendable {
309311
case console, fileSystem, messaging, narrative, plain, sourceCode, spreadsheet, wordProcessing
310312

311313
#if compiler(>=5.5.1)
@@ -325,7 +327,7 @@ extension TextState {
325327
#endif
326328
}
327329

328-
public enum AccessibilityHeadingLevel: String, Equatable, Hashable {
330+
public enum AccessibilityHeadingLevel: String, Equatable, Hashable, Sendable {
329331
case h1, h2, h3, h4, h5, h6, unspecified
330332

331333
#if compiler(>=5.5.1)

0 commit comments

Comments
 (0)