Skip to content

Commit e54ece6

Browse files
committed
[Swift 6] Update Sources for Swift 6
1 parent 668a657 commit e54ece6

Some content is hidden

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

58 files changed

+859
-830
lines changed

Sources/Introspect.swift

Lines changed: 15 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.
@@ -40,6 +40,7 @@ extension View {
4040
/// }
4141
/// }
4242
/// ```
43+
@MainActor
4344
public func introspect<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity>(
4445
_ viewType: SwiftUIViewType,
4546
on platforms: (PlatformViewVersionPredicate<SwiftUIViewType, PlatformSpecificEntity>)...,
@@ -56,6 +57,7 @@ struct IntrospectModifier<SwiftUIViewType: IntrospectableViewType, PlatformSpeci
5657
let selector: IntrospectionSelector<PlatformSpecificEntity>?
5758
let customize: (PlatformSpecificEntity) -> Void
5859

60+
@MainActor
5961
init(
6062
_ viewType: SwiftUIViewType,
6163
platforms: [PlatformViewVersionPredicate<SwiftUIViewType, PlatformSpecificEntity>],
@@ -100,37 +102,46 @@ public protocol PlatformEntity: AnyObject {
100102
associatedtype Base: PlatformEntity
101103

102104
@_spi(Internals)
105+
@MainActor
103106
var ancestor: Base? { get }
104107

105108
@_spi(Internals)
109+
@MainActor
106110
var descendants: [Base] { get }
107111

108112
@_spi(Internals)
113+
@MainActor
109114
func isDescendant(of other: Base) -> Bool
110115
}
111116

112117
extension PlatformEntity {
113118
@_spi(Internals)
119+
@MainActor
114120
public var ancestor: Base? { nil }
115121

116122
@_spi(Internals)
123+
@MainActor
117124
public var descendants: [Base] { [] }
118125

119126
@_spi(Internals)
127+
@MainActor
120128
public func isDescendant(of other: Base) -> Bool { false }
121129
}
122130

123131
extension PlatformEntity {
124132
@_spi(Internals)
133+
@MainActor
125134
public var ancestors: some Sequence<Base> {
126135
sequence(first: self~, next: { $0.ancestor~ }).dropFirst()
127136
}
128137

129138
@_spi(Internals)
139+
@MainActor
130140
public var allDescendants: some Sequence<Base> {
131141
recursiveSequence([self~], children: { $0.descendants~ }).dropFirst()
132142
}
133143

144+
@MainActor
134145
func nearestCommonAncestor(with other: Base) -> Base? {
135146
var nearestAncestor: Base? = self~
136147

@@ -141,13 +152,15 @@ extension PlatformEntity {
141152
return nearestAncestor
142153
}
143154

155+
@MainActor
144156
func allDescendants(between bottomEntity: Base, and topEntity: Base) -> some Sequence<Base> {
145157
self.allDescendants
146158
.lazy
147159
.drop(while: { $0 !== bottomEntity })
148160
.prefix(while: { $0 !== topEntity })
149161
}
150162

163+
@MainActor
151164
func receiver<PlatformSpecificEntity: PlatformEntity>(
152165
ofType type: PlatformSpecificEntity.Type
153166
) -> PlatformSpecificEntity? {
@@ -166,6 +179,7 @@ extension PlatformEntity {
166179
.first
167180
}
168181

182+
@MainActor
169183
func ancestor<PlatformSpecificEntity: PlatformEntity>(
170184
ofType type: PlatformSpecificEntity.Type
171185
) -> PlatformSpecificEntity? {

Sources/IntrospectableViewType.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#if !os(watchOS)
2+
@MainActor
23
public protocol IntrospectableViewType {
34
/// The scope of introspection for this particular view type, i.e. where introspect
45
/// should look to find the desired target view relative to the applied

Sources/IntrospectionSelector.swift

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

79
@_spi(Advanced)
8-
public static func from<Entry: PlatformEntity>(_ entryType: Entry.Type, selector: @escaping (Entry) -> Target?) -> Self {
10+
@MainActor
11+
public static func from<Entry: PlatformEntity>(_ entryType: Entry.Type, selector: @MainActor @escaping (Entry) -> Target?) -> Self {
912
.init(
1013
receiverSelector: { controller in
1114
controller.as(Entry.Base.self)?.receiver(ofType: Entry.self).flatMap(selector)
@@ -16,12 +19,12 @@ public struct IntrospectionSelector<Target: PlatformEntity> {
1619
)
1720
}
1821

19-
private var receiverSelector: (IntrospectionPlatformViewController) -> Target?
20-
private var ancestorSelector: (IntrospectionPlatformViewController) -> Target?
22+
private var receiverSelector: @MainActor (IntrospectionPlatformViewController) -> Target?
23+
private var ancestorSelector: @MainActor (IntrospectionPlatformViewController) -> Target?
2124

2225
private init(
23-
receiverSelector: @escaping (IntrospectionPlatformViewController) -> Target?,
24-
ancestorSelector: @escaping (IntrospectionPlatformViewController) -> Target?
26+
receiverSelector: @MainActor @escaping (IntrospectionPlatformViewController) -> Target?,
27+
ancestorSelector: @MainActor @escaping (IntrospectionPlatformViewController) -> Target?
2528
) {
2629
self.receiverSelector = receiverSelector
2730
self.ancestorSelector = ancestorSelector
@@ -41,6 +44,7 @@ public struct IntrospectionSelector<Target: PlatformEntity> {
4144
return copy
4245
}
4346

47+
@MainActor
4448
func callAsFunction(_ controller: IntrospectionPlatformViewController, _ scope: IntrospectionScope) -> Target? {
4549
if
4650
scope.contains(.receiver),

Sources/IntrospectionView.swift

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

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

910
struct Pair {
@@ -13,6 +14,7 @@ fileprivate enum IntrospectionStore {
1314
}
1415

1516
extension PlatformEntity {
17+
@MainActor
1618
var introspectionAnchorEntity: Base? {
1719
if let introspectionController = self as? IntrospectionPlatformViewController {
1820
return IntrospectionStore.shared[introspectionController.id]?.anchor~

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: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,30 @@ protocol PlatformViewControllerRepresentable: _PlatformViewControllerRepresentab
2626
typealias ViewController = NSViewControllerType
2727
#endif
2828

29-
func makePlatformViewController(context: Context) -> ViewController
30-
func updatePlatformViewController(_ controller: ViewController, context: Context)
31-
static func dismantlePlatformViewController(_ controller: ViewController, coordinator: Coordinator)
29+
@MainActor func makePlatformViewController(context: Context) -> ViewController
30+
@MainActor func updatePlatformViewController(_ controller: ViewController, context: Context)
31+
@MainActor static func dismantlePlatformViewController(_ controller: ViewController, coordinator: Coordinator)
3232
}
3333

3434
extension PlatformViewControllerRepresentable {
3535
#if canImport(UIKit)
36-
func makeUIViewController(context: Context) -> ViewController {
36+
@MainActor func makeUIViewController(context: Context) -> ViewController {
3737
makePlatformViewController(context: context)
3838
}
39-
func updateUIViewController(_ controller: ViewController, context: Context) {
39+
@MainActor func updateUIViewController(_ controller: ViewController, context: Context) {
4040
updatePlatformViewController(controller, context: context)
4141
}
42-
static func dismantleUIViewController(_ controller: ViewController, coordinator: Coordinator) {
42+
@MainActor static func dismantleUIViewController(_ controller: ViewController, coordinator: Coordinator) {
4343
dismantlePlatformViewController(controller, coordinator: coordinator)
4444
}
4545
#elseif canImport(AppKit)
46-
func makeNSViewController(context: Context) -> ViewController {
46+
@MainActor func makeNSViewController(context: Context) -> ViewController {
4747
makePlatformViewController(context: context)
4848
}
49-
func updateNSViewController(_ controller: ViewController, context: Context) {
49+
@MainActor func updateNSViewController(_ controller: ViewController, context: Context) {
5050
updatePlatformViewController(controller, context: context)
5151
}
52-
static func dismantleNSViewController(_ controller: ViewController, coordinator: Coordinator) {
52+
@MainActor static func dismantleNSViewController(_ controller: ViewController, coordinator: Coordinator) {
5353
dismantlePlatformViewController(controller, coordinator: coordinator)
5454
}
5555
#endif

Sources/PlatformViewVersion.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if !os(watchOS)
22
import SwiftUI
33

4+
@MainActor
45
public struct PlatformViewVersionPredicate<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity> {
56
let selector: IntrospectionSelector<PlatformSpecificEntity>?
67

@@ -94,6 +95,7 @@ public enum PlatformViewVersion<Version: PlatformVersion, SwiftUIViewType: Intro
9495
}
9596
}
9697

98+
@MainActor
9799
fileprivate var selector: IntrospectionSelector<PlatformSpecificEntity>? {
98100
if case .available(_, let selector) = self {
99101
return selector

Sources/RuntimeWarnings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func runtimeWarn(
5656
//
5757
// Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc
5858
@usableFromInline
59-
let dso = { () -> UnsafeMutableRawPointer in
59+
nonisolated(unsafe) let dso = { () -> UnsafeMutableRawPointer in
6060
let count = _dyld_image_count()
6161
for i in 0..<count {
6262
if let name = _dyld_get_image_name(i) {

Sources/ViewTypes/Button.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ public struct ButtonType: IntrospectableViewType {}
3131

3232
#if !os(iOS) && !os(tvOS) && !os(visionOS)
3333
extension IntrospectableViewType where Self == ButtonType {
34-
public static var button: Self { .init() }
34+
@MainActor public static var button: Self { .init() }
3535
}
3636

3737
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
3838
extension macOSViewVersion<ButtonType, NSButton> {
39-
public static let v10_15 = Self(for: .v10_15)
40-
public static let v11 = Self(for: .v11)
41-
public static let v12 = Self(for: .v12)
42-
public static let v13 = Self(for: .v13)
43-
public static let v14 = Self(for: .v14)
44-
public static let v15 = Self(for: .v15)
39+
@MainActor public static let v10_15 = Self(for: .v10_15)
40+
@MainActor public static let v11 = Self(for: .v11)
41+
@MainActor public static let v12 = Self(for: .v12)
42+
@MainActor public static let v13 = Self(for: .v13)
43+
@MainActor public static let v14 = Self(for: .v14)
44+
@MainActor public static let v15 = Self(for: .v15)
4545
}
4646
#endif
4747
#endif

Sources/ViewTypes/ColorPicker.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,35 +55,35 @@ public struct ColorPickerType: IntrospectableViewType {}
5555

5656
#if !os(tvOS)
5757
extension IntrospectableViewType where Self == ColorPickerType {
58-
public static var colorPicker: Self { .init() }
58+
@MainActor public static var colorPicker: Self { .init() }
5959
}
6060

6161
#if canImport(UIKit)
6262
@available(iOS 14, *)
6363
extension iOSViewVersion<ColorPickerType, UIColorWell> {
6464
@available(*, unavailable, message: "ColorPicker isn't available on iOS 13")
65-
public static let v13 = Self.unavailable()
66-
public static let v14 = Self(for: .v14)
67-
public static let v15 = Self(for: .v15)
68-
public static let v16 = Self(for: .v16)
69-
public static let v17 = Self(for: .v17)
70-
public static let v18 = Self(for: .v18)
65+
@MainActor public static let v13 = Self.unavailable()
66+
@MainActor public static let v14 = Self(for: .v14)
67+
@MainActor public static let v15 = Self(for: .v15)
68+
@MainActor public static let v16 = Self(for: .v16)
69+
@MainActor public static let v17 = Self(for: .v17)
70+
@MainActor public static let v18 = Self(for: .v18)
7171
}
7272

7373
@available(iOS 14, *)
7474
extension visionOSViewVersion<ColorPickerType, UIColorWell> {
75-
public static let v1 = Self(for: .v1)
75+
@MainActor public static let v1 = Self(for: .v1)
7676
}
7777
#elseif canImport(AppKit)
7878
@available(macOS 11, *)
7979
extension macOSViewVersion<ColorPickerType, NSColorWell> {
8080
@available(*, unavailable, message: "ColorPicker isn't available on macOS 10.15")
81-
public static let v10_15 = Self.unavailable()
82-
public static let v11 = Self(for: .v11)
83-
public static let v12 = Self(for: .v12)
84-
public static let v13 = Self(for: .v13)
85-
public static let v14 = Self(for: .v14)
86-
public static let v15 = Self(for: .v15)
81+
@MainActor public static let v10_15 = Self.unavailable()
82+
@MainActor public static let v11 = Self(for: .v11)
83+
@MainActor public static let v12 = Self(for: .v12)
84+
@MainActor public static let v13 = Self(for: .v13)
85+
@MainActor public static let v14 = Self(for: .v14)
86+
@MainActor public static let v15 = Self(for: .v15)
8787
}
8888
#endif
8989
#endif

Sources/ViewTypes/DatePicker.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,31 @@ public struct DatePickerType: IntrospectableViewType {}
5353

5454
#if !os(tvOS)
5555
extension IntrospectableViewType where Self == DatePickerType {
56-
public static var datePicker: Self { .init() }
56+
@MainActor public static var datePicker: Self { .init() }
5757
}
5858

5959
#if canImport(UIKit)
6060
extension iOSViewVersion<DatePickerType, UIDatePicker> {
61-
public static let v13 = Self(for: .v13)
62-
public static let v14 = Self(for: .v14)
63-
public static let v15 = Self(for: .v15)
64-
public static let v16 = Self(for: .v16)
65-
public static let v17 = Self(for: .v17)
66-
public static let v18 = Self(for: .v18)
61+
@MainActor public static let v13 = Self(for: .v13)
62+
@MainActor public static let v14 = Self(for: .v14)
63+
@MainActor public static let v15 = Self(for: .v15)
64+
@MainActor public static let v16 = Self(for: .v16)
65+
@MainActor public static let v17 = Self(for: .v17)
66+
@MainActor public static let v18 = Self(for: .v18)
6767
}
6868

6969
extension visionOSViewVersion<DatePickerType, UIDatePicker> {
70-
public static let v1 = Self(for: .v1)
71-
public static let v2 = Self(for: .v2)
70+
@MainActor public static let v1 = Self(for: .v1)
71+
@MainActor public static let v2 = Self(for: .v2)
7272
}
7373
#elseif canImport(AppKit)
7474
extension macOSViewVersion<DatePickerType, NSDatePicker> {
75-
public static let v10_15 = Self(for: .v10_15)
76-
public static let v11 = Self(for: .v11)
77-
public static let v12 = Self(for: .v12)
78-
public static let v13 = Self(for: .v13)
79-
public static let v14 = Self(for: .v14)
80-
public static let v15 = Self(for: .v15)
75+
@MainActor public static let v10_15 = Self(for: .v10_15)
76+
@MainActor public static let v11 = Self(for: .v11)
77+
@MainActor public static let v12 = Self(for: .v12)
78+
@MainActor public static let v13 = Self(for: .v13)
79+
@MainActor public static let v14 = Self(for: .v14)
80+
@MainActor public static let v15 = Self(for: .v15)
8181
}
8282
#endif
8383
#endif

0 commit comments

Comments
 (0)