Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix concurrency warnings #424

Merged
merged 8 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Examples/Showcase/Showcase.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@
SUPPORTS_MACCATALYST = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
TVOS_DEPLOYMENT_TARGET = 13.0;
XROS_DEPLOYMENT_TARGET = 1.0;
};
Expand Down Expand Up @@ -268,6 +270,8 @@
SUPPORTS_MACCATALYST = YES;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
TVOS_DEPLOYMENT_TARGET = 13.0;
VALIDATE_PRODUCT = YES;
XROS_DEPLOYMENT_TARGET = 1.0;
Expand Down
4 changes: 4 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ let package = Package(
name: "SwiftUIIntrospect",
path: "Sources"
),
],
swiftLanguageVersions: [
.v5,
.version("6.0"),
]
)
3 changes: 2 additions & 1 deletion Sources/Introspect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwiftUI
/// The scope of introspection i.e. where introspect should look to find
/// the desired target view relative to the applied `.introspect(...)`
/// modifier.
public struct IntrospectionScope: OptionSet {
public struct IntrospectionScope: OptionSet, Sendable {
/// Look within the `receiver` of the `.introspect(...)` modifier.
public static let receiver = Self(rawValue: 1 << 0)
/// Look for an `ancestor` relative to the `.introspect(...)` modifier.
Expand Down Expand Up @@ -96,6 +96,7 @@ struct IntrospectModifier<SwiftUIViewType: IntrospectableViewType, PlatformSpeci
}
}

@MainActor
public protocol PlatformEntity: AnyObject {
associatedtype Base: PlatformEntity

Expand Down
18 changes: 9 additions & 9 deletions Sources/IntrospectionSelector.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#if !os(watchOS)
@_spi(Advanced)
public struct IntrospectionSelector<Target: PlatformEntity> {
public struct IntrospectionSelector<Target: PlatformEntity>: Sendable {
@_spi(Advanced)
public static var `default`: Self { .from(Target.self, selector: { $0 }) }

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

private var receiverSelector: (IntrospectionPlatformViewController) -> Target?
private var ancestorSelector: (IntrospectionPlatformViewController) -> Target?
private var receiverSelector: @MainActor @Sendable (IntrospectionPlatformViewController) -> Target?
private var ancestorSelector: @MainActor @Sendable (IntrospectionPlatformViewController) -> Target?

private init(
receiverSelector: @escaping (IntrospectionPlatformViewController) -> Target?,
ancestorSelector: @escaping (IntrospectionPlatformViewController) -> Target?
receiverSelector: @MainActor @Sendable @escaping (IntrospectionPlatformViewController) -> Target?,
ancestorSelector: @MainActor @Sendable @escaping (IntrospectionPlatformViewController) -> Target?
) {
self.receiverSelector = receiverSelector
self.ancestorSelector = ancestorSelector
}

@_spi(Advanced)
public func withReceiverSelector(_ selector: @escaping (PlatformViewController) -> Target?) -> Self {
public func withReceiverSelector(_ selector: @MainActor @Sendable @escaping (PlatformViewController) -> Target?) -> Self {
var copy = self
copy.receiverSelector = selector
return copy
}

@_spi(Advanced)
public func withAncestorSelector(_ selector: @escaping (PlatformViewController) -> Target?) -> Self {
public func withAncestorSelector(_ selector: @MainActor @Sendable @escaping (PlatformViewController) -> Target?) -> Self {
var copy = self
copy.ancestorSelector = selector
return copy
}

func callAsFunction(_ controller: IntrospectionPlatformViewController, _ scope: IntrospectionScope) -> Target? {
@MainActor func callAsFunction(_ controller: IntrospectionPlatformViewController, _ scope: IntrospectionScope) -> Target? {
if
scope.contains(.receiver),
let target = receiverSelector(controller)
Expand Down
4 changes: 2 additions & 2 deletions Sources/IntrospectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwiftUI
typealias IntrospectionViewID = UUID

fileprivate enum IntrospectionStore {
static var shared: [IntrospectionViewID: Pair] = [:]
@MainActor static var shared: [IntrospectionViewID: Pair] = [:]

struct Pair {
weak var controller: IntrospectionPlatformViewController?
Expand All @@ -13,7 +13,7 @@ fileprivate enum IntrospectionStore {
}

extension PlatformEntity {
var introspectionAnchorEntity: Base? {
@MainActor var introspectionAnchorEntity: Base? {
if let introspectionController = self as? IntrospectionPlatformViewController {
return IntrospectionStore.shared[introspectionController.id]?.anchor~
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/PlatformVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import Foundation

@_spi(Internals)
public enum PlatformVersionCondition {
public enum PlatformVersionCondition: Sendable {
case past
case current
case future
}

public protocol PlatformVersion {
public protocol PlatformVersion: Sendable {
@_spi(Internals)
var condition: PlatformVersionCondition? { get }
}
Expand Down
1 change: 1 addition & 0 deletions Sources/PlatformView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ typealias _PlatformViewControllerRepresentable = UIViewControllerRepresentable
typealias _PlatformViewControllerRepresentable = NSViewControllerRepresentable
#endif

@MainActor
protocol PlatformViewControllerRepresentable: _PlatformViewControllerRepresentable {
#if canImport(UIKit)
typealias ViewController = UIViewControllerType
Expand Down
4 changes: 2 additions & 2 deletions Sources/PlatformViewVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public typealias macOSViewVersion<SwiftUIViewType: IntrospectableViewType, Platf
public typealias visionOSViewVersion<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity> =
PlatformViewVersion<visionOSVersion, SwiftUIViewType, PlatformSpecificEntity>

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

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

Expand Down
83 changes: 0 additions & 83 deletions Sources/RuntimeWarnings.swift

This file was deleted.

6 changes: 3 additions & 3 deletions Sources/ViewTypes/FullScreenCover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extension iOSViewVersion<FullScreenCoverType, UIPresentationController> {
public static let v18 = Self(for: .v18, selector: selector)

private static var selector: IntrospectionSelector<UIPresentationController> {
.from(UIViewController.self, selector: \.presentationController)
.from(UIViewController.self, selector: { $0.presentationController })
}
}

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

private static var selector: IntrospectionSelector<UIPresentationController> {
.from(UIViewController.self, selector: \.presentationController)
.from(UIViewController.self, selector: { $0.presentationController })
}
}

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

private static var selector: IntrospectionSelector<UIPresentationController> {
.from(UIViewController.self, selector: \.presentationController)
.from(UIViewController.self, selector: { $0.presentationController })
}
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions Sources/ViewTypes/NavigationSplitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension iOSViewVersion<NavigationSplitViewType, UISplitViewController> {
public static let v18 = Self(for: .v18, selector: selector)

private static var selector: IntrospectionSelector<UISplitViewController> {
.default.withAncestorSelector(\.splitViewController)
.default.withAncestorSelector({ $0.splitViewController })
}
}

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

private static var selector: IntrospectionSelector<UINavigationController> {
.default.withAncestorSelector(\.navigationController)
.default.withAncestorSelector { $0.navigationController }
}
}

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

private static var selector: IntrospectionSelector<UISplitViewController> {
.default.withAncestorSelector(\.splitViewController)
.default.withAncestorSelector { $0.splitViewController }
}
}
#elseif canImport(AppKit)
Expand Down
6 changes: 3 additions & 3 deletions Sources/ViewTypes/NavigationStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extension iOSViewVersion<NavigationStackType, UINavigationController> {
public static let v18 = Self(for: .v18, selector: selector)

private static var selector: IntrospectionSelector<UINavigationController> {
.default.withAncestorSelector(\.navigationController)
.default.withAncestorSelector { $0.navigationController }
}
}

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

private static var selector: IntrospectionSelector<UINavigationController> {
.default.withAncestorSelector(\.navigationController)
.default.withAncestorSelector { $0.navigationController }
}
}

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

private static var selector: IntrospectionSelector<UINavigationController> {
.default.withAncestorSelector(\.navigationController)
.default.withAncestorSelector { $0.navigationController }
}
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions Sources/ViewTypes/NavigationViewWithColumnsStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extension iOSViewVersion<NavigationViewWithColumnsStyleType, UISplitViewControll
public static let v18 = Self(for: .v18, selector: selector)

private static var selector: IntrospectionSelector<UISplitViewController> {
.default.withAncestorSelector(\.splitViewController)
.default.withAncestorSelector { $0.splitViewController }
}
}

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

private static var selector: IntrospectionSelector<UINavigationController> {
.default.withAncestorSelector(\.navigationController)
.default.withAncestorSelector { $0.navigationController }
}
}

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

private static var selector: IntrospectionSelector<UISplitViewController> {
.default.withAncestorSelector(\.splitViewController)
.default.withAncestorSelector { $0.splitViewController }
}
}
#elseif canImport(AppKit)
Expand Down
6 changes: 3 additions & 3 deletions Sources/ViewTypes/NavigationViewWithStackStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extension iOSViewVersion<NavigationViewWithStackStyleType, UINavigationControlle
public static let v18 = Self(for: .v18, selector: selector)

private static var selector: IntrospectionSelector<UINavigationController> {
.default.withAncestorSelector(\.navigationController)
.default.withAncestorSelector { $0.navigationController }
}
}

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

private static var selector: IntrospectionSelector<UINavigationController> {
.default.withAncestorSelector(\.navigationController)
.default.withAncestorSelector { $0.navigationController }
}
}

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

private static var selector: IntrospectionSelector<UINavigationController> {
.default.withAncestorSelector(\.navigationController)
.default.withAncestorSelector { $0.navigationController }
}
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions Sources/ViewTypes/Popover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension iOSViewVersion<PopoverType, UIPopoverPresentationController> {
public static let v18 = Self(for: .v18, selector: selector)

private static var selector: IntrospectionSelector<UIPopoverPresentationController> {
.from(UIViewController.self, selector: \.popoverPresentationController)
.from(UIViewController.self, selector: { $0.popoverPresentationController })
}
}

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

private static var selector: IntrospectionSelector<UIPopoverPresentationController> {
.from(UIViewController.self, selector: \.popoverPresentationController)
.from(UIViewController.self, selector: { $0.popoverPresentationController })
}
}
#endif
Expand Down
Loading
Loading