Skip to content

Commit 9068014

Browse files
Fix concurrency warnings (#424)
Co-authored-by: David Roman <[email protected]>
1 parent 668a657 commit 9068014

File tree

72 files changed

+113
-126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+113
-126
lines changed

Examples/Showcase/Showcase.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@
209209
SUPPORTS_MACCATALYST = YES;
210210
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
211211
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
212+
SWIFT_STRICT_CONCURRENCY = complete;
213+
SWIFT_VERSION = 6.0;
212214
TVOS_DEPLOYMENT_TARGET = 13.0;
213215
XROS_DEPLOYMENT_TARGET = 1.0;
214216
};
@@ -268,6 +270,8 @@
268270
SUPPORTS_MACCATALYST = YES;
269271
SWIFT_COMPILATION_MODE = wholemodule;
270272
SWIFT_OPTIMIZATION_LEVEL = "-O";
273+
SWIFT_STRICT_CONCURRENCY = complete;
274+
SWIFT_VERSION = 6.0;
271275
TVOS_DEPLOYMENT_TARGET = 13.0;
272276
VALIDATE_PRODUCT = YES;
273277
XROS_DEPLOYMENT_TARGET = 1.0;

Package.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ let package = Package(
1919
name: "SwiftUIIntrospect",
2020
path: "Sources"
2121
),
22+
],
23+
swiftLanguageVersions: [
24+
.v5,
25+
.version("6.0"),
2226
]
2327
)

Sources/Introspect.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SwiftUI
44
/// The scope of introspection i.e. where introspect should look to find
55
/// the desired target view relative to the applied `.introspect(...)`
66
/// modifier.
7-
public struct IntrospectionScope: OptionSet {
7+
public struct IntrospectionScope: OptionSet, Sendable {
88
/// Look within the `receiver` of the `.introspect(...)` modifier.
99
public static let receiver = Self(rawValue: 1 << 0)
1010
/// Look for an `ancestor` relative to the `.introspect(...)` modifier.
@@ -96,6 +96,7 @@ struct IntrospectModifier<SwiftUIViewType: IntrospectableViewType, PlatformSpeci
9696
}
9797
}
9898

99+
@MainActor
99100
public protocol PlatformEntity: AnyObject {
100101
associatedtype Base: PlatformEntity
101102

Sources/IntrospectionSelector.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#if !os(watchOS)
22
@_spi(Advanced)
3-
public struct IntrospectionSelector<Target: PlatformEntity> {
3+
public struct IntrospectionSelector<Target: PlatformEntity>: Sendable {
44
@_spi(Advanced)
55
public static var `default`: Self { .from(Target.self, selector: { $0 }) }
66

77
@_spi(Advanced)
8-
public static func from<Entry: PlatformEntity>(_ entryType: Entry.Type, selector: @escaping (Entry) -> Target?) -> Self {
8+
public static func from<Entry: PlatformEntity>(_ entryType: Entry.Type, selector: @MainActor @Sendable @escaping (Entry) -> Target?) -> Self {
99
.init(
1010
receiverSelector: { controller in
1111
controller.as(Entry.Base.self)?.receiver(ofType: Entry.self).flatMap(selector)
@@ -16,32 +16,32 @@ public struct IntrospectionSelector<Target: PlatformEntity> {
1616
)
1717
}
1818

19-
private var receiverSelector: (IntrospectionPlatformViewController) -> Target?
20-
private var ancestorSelector: (IntrospectionPlatformViewController) -> Target?
19+
private var receiverSelector: @MainActor @Sendable (IntrospectionPlatformViewController) -> Target?
20+
private var ancestorSelector: @MainActor @Sendable (IntrospectionPlatformViewController) -> Target?
2121

2222
private init(
23-
receiverSelector: @escaping (IntrospectionPlatformViewController) -> Target?,
24-
ancestorSelector: @escaping (IntrospectionPlatformViewController) -> Target?
23+
receiverSelector: @MainActor @Sendable @escaping (IntrospectionPlatformViewController) -> Target?,
24+
ancestorSelector: @MainActor @Sendable @escaping (IntrospectionPlatformViewController) -> Target?
2525
) {
2626
self.receiverSelector = receiverSelector
2727
self.ancestorSelector = ancestorSelector
2828
}
2929

3030
@_spi(Advanced)
31-
public func withReceiverSelector(_ selector: @escaping (PlatformViewController) -> Target?) -> Self {
31+
public func withReceiverSelector(_ selector: @MainActor @Sendable @escaping (PlatformViewController) -> Target?) -> Self {
3232
var copy = self
3333
copy.receiverSelector = selector
3434
return copy
3535
}
3636

3737
@_spi(Advanced)
38-
public func withAncestorSelector(_ selector: @escaping (PlatformViewController) -> Target?) -> Self {
38+
public func withAncestorSelector(_ selector: @MainActor @Sendable @escaping (PlatformViewController) -> Target?) -> Self {
3939
var copy = self
4040
copy.ancestorSelector = selector
4141
return copy
4242
}
4343

44-
func callAsFunction(_ controller: IntrospectionPlatformViewController, _ scope: IntrospectionScope) -> Target? {
44+
@MainActor func callAsFunction(_ controller: IntrospectionPlatformViewController, _ scope: IntrospectionScope) -> Target? {
4545
if
4646
scope.contains(.receiver),
4747
let target = receiverSelector(controller)

Sources/IntrospectionView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SwiftUI
44
typealias IntrospectionViewID = UUID
55

66
fileprivate enum IntrospectionStore {
7-
static var shared: [IntrospectionViewID: Pair] = [:]
7+
@MainActor static var shared: [IntrospectionViewID: Pair] = [:]
88

99
struct Pair {
1010
weak var controller: IntrospectionPlatformViewController?
@@ -13,7 +13,7 @@ fileprivate enum IntrospectionStore {
1313
}
1414

1515
extension PlatformEntity {
16-
var introspectionAnchorEntity: Base? {
16+
@MainActor var introspectionAnchorEntity: Base? {
1717
if let introspectionController = self as? IntrospectionPlatformViewController {
1818
return IntrospectionStore.shared[introspectionController.id]?.anchor~
1919
}

Sources/PlatformVersion.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import Foundation
33

44
@_spi(Internals)
5-
public enum PlatformVersionCondition {
5+
public enum PlatformVersionCondition: Sendable {
66
case past
77
case current
88
case future
99
}
1010

11-
public protocol PlatformVersion {
11+
public protocol PlatformVersion: Sendable {
1212
@_spi(Internals)
1313
var condition: PlatformVersionCondition? { get }
1414
}

Sources/PlatformView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typealias _PlatformViewControllerRepresentable = UIViewControllerRepresentable
1919
typealias _PlatformViewControllerRepresentable = NSViewControllerRepresentable
2020
#endif
2121

22+
@MainActor
2223
protocol PlatformViewControllerRepresentable: _PlatformViewControllerRepresentable {
2324
#if canImport(UIKit)
2425
typealias ViewController = UIViewControllerType

Sources/PlatformViewVersion.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public typealias macOSViewVersion<SwiftUIViewType: IntrospectableViewType, Platf
6161
public typealias visionOSViewVersion<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity> =
6262
PlatformViewVersion<visionOSVersion, SwiftUIViewType, PlatformSpecificEntity>
6363

64-
public enum PlatformViewVersion<Version: PlatformVersion, SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity> {
64+
public enum PlatformViewVersion<Version: PlatformVersion, SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity>: Sendable {
6565
@_spi(Internals) case available(Version, IntrospectionSelector<PlatformSpecificEntity>?)
6666
@_spi(Internals) case unavailable
6767

@@ -72,7 +72,7 @@ public enum PlatformViewVersion<Version: PlatformVersion, SwiftUIViewType: Intro
7272
@_spi(Advanced) public static func unavailable(file: StaticString = #file, line: UInt = #line) -> Self {
7373
let filePath = file.withUTF8Buffer { String(decoding: $0, as: UTF8.self) }
7474
let fileName = URL(fileURLWithPath: filePath).lastPathComponent
75-
runtimeWarn(
75+
print(
7676
"""
7777
If you're seeing this, someone forgot to mark \(fileName):\(line) as unavailable.
7878

Sources/RuntimeWarnings.swift

Lines changed: 0 additions & 83 deletions
This file was deleted.

Sources/ViewTypes/FullScreenCover.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ extension iOSViewVersion<FullScreenCoverType, UIPresentationController> {
8080
public static let v18 = Self(for: .v18, selector: selector)
8181

8282
private static var selector: IntrospectionSelector<UIPresentationController> {
83-
.from(UIViewController.self, selector: \.presentationController)
83+
.from(UIViewController.self, selector: { $0.presentationController })
8484
}
8585
}
8686

@@ -94,7 +94,7 @@ extension tvOSViewVersion<FullScreenCoverType, UIPresentationController> {
9494
public static let v18 = Self(for: .v18, selector: selector)
9595

9696
private static var selector: IntrospectionSelector<UIPresentationController> {
97-
.from(UIViewController.self, selector: \.presentationController)
97+
.from(UIViewController.self, selector: { $0.presentationController })
9898
}
9999
}
100100

@@ -103,7 +103,7 @@ extension visionOSViewVersion<FullScreenCoverType, UIPresentationController> {
103103
public static let v2 = Self(for: .v2, selector: selector)
104104

105105
private static var selector: IntrospectionSelector<UIPresentationController> {
106-
.from(UIViewController.self, selector: \.presentationController)
106+
.from(UIViewController.self, selector: { $0.presentationController })
107107
}
108108
}
109109
#endif

Sources/ViewTypes/NavigationSplitView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ extension iOSViewVersion<NavigationSplitViewType, UISplitViewController> {
9090
public static let v18 = Self(for: .v18, selector: selector)
9191

9292
private static var selector: IntrospectionSelector<UISplitViewController> {
93-
.default.withAncestorSelector(\.splitViewController)
93+
.default.withAncestorSelector({ $0.splitViewController })
9494
}
9595
}
9696

@@ -107,7 +107,7 @@ extension tvOSViewVersion<NavigationSplitViewType, UINavigationController> {
107107
public static let v18 = Self(for: .v18, selector: selector)
108108

109109
private static var selector: IntrospectionSelector<UINavigationController> {
110-
.default.withAncestorSelector(\.navigationController)
110+
.default.withAncestorSelector { $0.navigationController }
111111
}
112112
}
113113

@@ -116,7 +116,7 @@ extension visionOSViewVersion<NavigationSplitViewType, UISplitViewController> {
116116
public static let v2 = Self(for: .v2, selector: selector)
117117

118118
private static var selector: IntrospectionSelector<UISplitViewController> {
119-
.default.withAncestorSelector(\.splitViewController)
119+
.default.withAncestorSelector { $0.splitViewController }
120120
}
121121
}
122122
#elseif canImport(AppKit)

Sources/ViewTypes/NavigationStack.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ extension iOSViewVersion<NavigationStackType, UINavigationController> {
7171
public static let v18 = Self(for: .v18, selector: selector)
7272

7373
private static var selector: IntrospectionSelector<UINavigationController> {
74-
.default.withAncestorSelector(\.navigationController)
74+
.default.withAncestorSelector { $0.navigationController }
7575
}
7676
}
7777

@@ -88,7 +88,7 @@ extension tvOSViewVersion<NavigationStackType, UINavigationController> {
8888
public static let v18 = Self(for: .v18, selector: selector)
8989

9090
private static var selector: IntrospectionSelector<UINavigationController> {
91-
.default.withAncestorSelector(\.navigationController)
91+
.default.withAncestorSelector { $0.navigationController }
9292
}
9393
}
9494

@@ -97,7 +97,7 @@ extension visionOSViewVersion<NavigationStackType, UINavigationController> {
9797
public static let v2 = Self(for: .v2, selector: selector)
9898

9999
private static var selector: IntrospectionSelector<UINavigationController> {
100-
.default.withAncestorSelector(\.navigationController)
100+
.default.withAncestorSelector { $0.navigationController }
101101
}
102102
}
103103
#endif

Sources/ViewTypes/NavigationViewWithColumnsStyle.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extension iOSViewVersion<NavigationViewWithColumnsStyleType, UISplitViewControll
8686
public static let v18 = Self(for: .v18, selector: selector)
8787

8888
private static var selector: IntrospectionSelector<UISplitViewController> {
89-
.default.withAncestorSelector(\.splitViewController)
89+
.default.withAncestorSelector { $0.splitViewController }
9090
}
9191
}
9292

@@ -99,7 +99,7 @@ extension tvOSViewVersion<NavigationViewWithColumnsStyleType, UINavigationContro
9999
public static let v18 = Self(for: .v18, selector: selector)
100100

101101
private static var selector: IntrospectionSelector<UINavigationController> {
102-
.default.withAncestorSelector(\.navigationController)
102+
.default.withAncestorSelector { $0.navigationController }
103103
}
104104
}
105105

@@ -108,7 +108,7 @@ extension visionOSViewVersion<NavigationViewWithColumnsStyleType, UISplitViewCon
108108
public static let v2 = Self(for: .v2, selector: selector)
109109

110110
private static var selector: IntrospectionSelector<UISplitViewController> {
111-
.default.withAncestorSelector(\.splitViewController)
111+
.default.withAncestorSelector { $0.splitViewController }
112112
}
113113
}
114114
#elseif canImport(AppKit)

Sources/ViewTypes/NavigationViewWithStackStyle.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extension iOSViewVersion<NavigationViewWithStackStyleType, UINavigationControlle
7474
public static let v18 = Self(for: .v18, selector: selector)
7575

7676
private static var selector: IntrospectionSelector<UINavigationController> {
77-
.default.withAncestorSelector(\.navigationController)
77+
.default.withAncestorSelector { $0.navigationController }
7878
}
7979
}
8080

@@ -87,7 +87,7 @@ extension tvOSViewVersion<NavigationViewWithStackStyleType, UINavigationControll
8787
public static let v18 = Self(for: .v18, selector: selector)
8888

8989
private static var selector: IntrospectionSelector<UINavigationController> {
90-
.default.withAncestorSelector(\.navigationController)
90+
.default.withAncestorSelector { $0.navigationController }
9191
}
9292
}
9393

@@ -96,7 +96,7 @@ extension visionOSViewVersion<NavigationViewWithStackStyleType, UINavigationCont
9696
public static let v2 = Self(for: .v2, selector: selector)
9797

9898
private static var selector: IntrospectionSelector<UINavigationController> {
99-
.default.withAncestorSelector(\.navigationController)
99+
.default.withAncestorSelector { $0.navigationController }
100100
}
101101
}
102102
#endif

Sources/ViewTypes/Popover.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extension iOSViewVersion<PopoverType, UIPopoverPresentationController> {
6565
public static let v18 = Self(for: .v18, selector: selector)
6666

6767
private static var selector: IntrospectionSelector<UIPopoverPresentationController> {
68-
.from(UIViewController.self, selector: \.popoverPresentationController)
68+
.from(UIViewController.self, selector: { $0.popoverPresentationController })
6969
}
7070
}
7171

@@ -74,7 +74,7 @@ extension visionOSViewVersion<PopoverType, UIPopoverPresentationController> {
7474
public static let v2 = Self(for: .v2, selector: selector)
7575

7676
private static var selector: IntrospectionSelector<UIPopoverPresentationController> {
77-
.from(UIViewController.self, selector: \.popoverPresentationController)
77+
.from(UIViewController.self, selector: { $0.popoverPresentationController })
7878
}
7979
}
8080
#endif

0 commit comments

Comments
 (0)