Skip to content
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
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.0
23 changes: 23 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SwiftFormat Configuration File
# For documentation, see: https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md

--header ignore
--indent tab
--ifdef preserve
--ranges preserve
--extensionacl on-declarations
--trailing-commas always
--nil-init insert

# Disabled rules
--disable blankLinesAroundMark
--disable blankLinesBetweenScopes
--disable docComments
--disable redundantBackticks
--disable redundantLetError
--disable redundantRawValues
--disable redundantSelf
--disable redundantStaticSelf
--disable redundantType
--disable redundantTypedThrows
--disable unusedArguments
6 changes: 3 additions & 3 deletions Examples/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import PackageDescription

let package = Package(
name: "Examples",
products: [],
targets: []
name: "Examples",
products: [],
targets: []
)
2 changes: 0 additions & 2 deletions Examples/Showcase/Showcase/Controls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import SwiftUI
import SwiftUIIntrospect

struct ControlsShowcase: View {

@State private var textFieldValue = ""
@State private var toggleValue = false
@State private var sliderValue = 0.0
Expand Down Expand Up @@ -166,6 +165,5 @@ struct ControlsShowcase: View {
#endif
}
}

}
}
13 changes: 6 additions & 7 deletions Examples/Showcase/Showcase/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ struct ListShowcase: View {
.modifier { list in
if #available(iOS 16, macOS 13, *) {
list.background {
if receiverListFound {
Color(.cyan)
}
if receiverListFound {
Color(.cyan)
}
#if !os(tvOS)
.scrollContentBackground(.hidden)
#endif
}
#if !os(tvOS)
.scrollContentBackground(.hidden)
#endif
} else {
list
}
Expand Down Expand Up @@ -104,6 +104,5 @@ struct ListShowcase: View {
}
}
}

}
}
8 changes: 4 additions & 4 deletions Sources/Introspect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ extension View {
/// ```
@MainActor
public func introspect<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity>(
_ viewType: SwiftUIViewType,
on platforms: (PlatformViewVersionPredicate<SwiftUIViewType, PlatformSpecificEntity>)...,
scope: IntrospectionScope? = nil,
customize: @escaping (PlatformSpecificEntity) -> Void
_ viewType: SwiftUIViewType,
on platforms: PlatformViewVersionPredicate<SwiftUIViewType, PlatformSpecificEntity>...,
scope: IntrospectionScope? = nil,
customize: @escaping (PlatformSpecificEntity) -> Void
) -> some View {
self.modifier(IntrospectModifier(viewType, platforms: platforms, scope: scope, customize: customize))
}
Expand Down
9 changes: 4 additions & 5 deletions Sources/IntrospectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ fileprivate enum IntrospectionStore {
static var shared: [IntrospectionViewID: Pair] = [:]

struct Pair {
weak var controller: IntrospectionPlatformViewController?
weak var anchor: IntrospectionAnchorPlatformViewController?
weak var controller: IntrospectionPlatformViewController? = nil
weak var anchor: IntrospectionAnchorPlatformViewController? = nil
}
}

Expand Down Expand Up @@ -88,7 +88,7 @@ struct IntrospectionView<Target: PlatformEntity>: PlatformViewControllerRepresen
#endif

final class TargetCache {
weak var target: Target?
weak var target: Target? = nil
}

@Binding
Expand All @@ -113,15 +113,14 @@ struct IntrospectionView<Target: PlatformEntity>: PlatformViewControllerRepresen
}

func makePlatformViewController(context: Context) -> IntrospectionPlatformViewController {
let controller = IntrospectionPlatformViewController(id: id) { controller in
IntrospectionPlatformViewController(id: id) { controller in
guard let target = selector(controller) else {
return
}
context.coordinator.target = target
customize(target)
controller.handler = nil
}
return controller
}

func updatePlatformViewController(_ controller: IntrospectionPlatformViewController, context: Context) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/PlatformVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension PlatformVersion {
public var isCurrentOrPast: Bool {
condition == .current || condition == .past
}

@_spi(Internals)
public var condition: PlatformVersionCondition? { nil }
}
Expand Down Expand Up @@ -206,7 +206,7 @@ extension tvOSVersion {
return nil
#endif
}

public static let v17 = tvOSVersion {
#if os(tvOS)
if #available(tvOS 18, *) {
Expand Down
14 changes: 7 additions & 7 deletions Sources/PlatformView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ public protocol PlatformViewControllerRepresentable: _PlatformViewControllerRepr
}

@_spi(Internals)
public extension PlatformViewControllerRepresentable {
extension PlatformViewControllerRepresentable {
#if canImport(UIKit)
func makeUIViewController(context: Context) -> ViewController {
public func makeUIViewController(context: Context) -> ViewController {
makePlatformViewController(context: context)
}
func updateUIViewController(_ controller: ViewController, context: Context) {
public func updateUIViewController(_ controller: ViewController, context: Context) {
updatePlatformViewController(controller, context: context)
}
static func dismantleUIViewController(_ controller: ViewController, coordinator: Coordinator) {
public static func dismantleUIViewController(_ controller: ViewController, coordinator: Coordinator) {
dismantlePlatformViewController(controller, coordinator: coordinator)
}
#elseif canImport(AppKit)
func makeNSViewController(context: Context) -> ViewController {
public func makeNSViewController(context: Context) -> ViewController {
makePlatformViewController(context: context)
}
func updateNSViewController(_ controller: ViewController, context: Context) {
public func updateNSViewController(_ controller: ViewController, context: Context) {
updatePlatformViewController(controller, context: context)
}
static func dismantleNSViewController(_ controller: ViewController, coordinator: Coordinator) {
public static func dismantleNSViewController(_ controller: ViewController, coordinator: Coordinator) {
dismantlePlatformViewController(controller, coordinator: coordinator)
}
#endif
Expand Down
24 changes: 12 additions & 12 deletions Sources/PlatformViewVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct PlatformViewVersionPredicate<SwiftUIViewType: IntrospectableViewTy
}
}

public static func iOS(_ versions: (iOSViewVersion<SwiftUIViewType, PlatformSpecificEntity>)...) -> Self {
public static func iOS(_ versions: iOSViewVersion<SwiftUIViewType, PlatformSpecificEntity>...) -> Self {
Self(versions, matches: \.isCurrent)
}

Expand All @@ -25,7 +25,7 @@ public struct PlatformViewVersionPredicate<SwiftUIViewType: IntrospectableViewTy
Self([versions.lowerBound], matches: \.isCurrentOrPast)
}

public static func tvOS(_ versions: (tvOSViewVersion<SwiftUIViewType, PlatformSpecificEntity>)...) -> Self {
public static func tvOS(_ versions: tvOSViewVersion<SwiftUIViewType, PlatformSpecificEntity>...) -> Self {
Self(versions, matches: \.isCurrent)
}

Expand All @@ -34,7 +34,7 @@ public struct PlatformViewVersionPredicate<SwiftUIViewType: IntrospectableViewTy
Self([versions.lowerBound], matches: \.isCurrentOrPast)
}

public static func macOS(_ versions: (macOSViewVersion<SwiftUIViewType, PlatformSpecificEntity>)...) -> Self {
public static func macOS(_ versions: macOSViewVersion<SwiftUIViewType, PlatformSpecificEntity>...) -> Self {
Self(versions, matches: \.isCurrent)
}

Expand All @@ -43,7 +43,7 @@ public struct PlatformViewVersionPredicate<SwiftUIViewType: IntrospectableViewTy
Self([versions.lowerBound], matches: \.isCurrentOrPast)
}

public static func visionOS(_ versions: (visionOSViewVersion<SwiftUIViewType, PlatformSpecificEntity>)...) -> Self {
public static func visionOS(_ versions: visionOSViewVersion<SwiftUIViewType, PlatformSpecificEntity>...) -> Self {
Self(versions, matches: \.isCurrent)
}

Expand Down Expand Up @@ -89,19 +89,19 @@ public enum PlatformViewVersion<Version: PlatformVersion, SwiftUIViewType: Intro
}

private var version: Version? {
if case .available(let version, _) = self {
return version
if case let .available(version, _) = self {
version
} else {
return nil
nil
}
}

@MainActor
fileprivate var selector: IntrospectionSelector<PlatformSpecificEntity>? {
if case .available(_, let selector) = self {
return selector
if case let .available(_, selector) = self {
selector
} else {
return nil
nil
}
}

Expand All @@ -117,11 +117,11 @@ public enum PlatformViewVersion<Version: PlatformVersion, SwiftUIViewType: Intro
// This conformance isn't meant to be used directly by the user,
// it's only to satisfy requirements for forming ranges (e.g. `.v15...`).
extension PlatformViewVersion: Comparable {
nonisolated public static func == (lhs: Self, rhs: Self) -> Bool {
public nonisolated static func == (lhs: Self, rhs: Self) -> Bool {
true
}

nonisolated public static func < (lhs: Self, rhs: Self) -> Bool {
public nonisolated static func < (lhs: Self, rhs: Self) -> Bool {
true
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Utils.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
postfix operator ~

postfix func ~ <LHS, T>(lhs: LHS) -> T {
postfix func ~ <T>(lhs: some Any) -> T {
lhs as! T
}

postfix func ~ <LHS, T>(lhs: LHS?) -> T? {
postfix func ~ <T>(lhs: (some Any)?) -> T? {
lhs as? T
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Weak.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@_spi(Advanced)
@propertyWrapper
public final class Weak<T: AnyObject> {
private weak var _wrappedValue: T?
private weak var _wrappedValue: T? = nil

public var wrappedValue: T? {
get { _wrappedValue }
Expand Down
14 changes: 7 additions & 7 deletions Tests/Tests/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func introspection<Entity: AnyObject & Sendable>(
{
confirmation1()
entity1 = $0
},
}
)

TestUtils.present(view: view)
Expand Down Expand Up @@ -98,7 +98,7 @@ func introspection<Entity: AnyObject & Sendable>(
{
confirmation2()
entity2 = $0
},
}
)

TestUtils.present(view: view)
Expand All @@ -114,7 +114,7 @@ func introspection<Entity: AnyObject & Sendable>(

return try (
#require(entity1, sourceLocation: sourceLocation),
#require(entity2, sourceLocation: sourceLocation),
#require(entity2, sourceLocation: sourceLocation)
)
}
}
Expand Down Expand Up @@ -150,7 +150,7 @@ func introspection<Entity: AnyObject & Sendable>(
{
confirmation3()
entity3 = $0
},
}
)

TestUtils.present(view: view)
Expand All @@ -168,7 +168,7 @@ func introspection<Entity: AnyObject & Sendable>(
return try (
#require(entity1, sourceLocation: sourceLocation),
#require(entity2, sourceLocation: sourceLocation),
#require(entity3, sourceLocation: sourceLocation),
#require(entity3, sourceLocation: sourceLocation)
)
}
}
Expand Down Expand Up @@ -212,7 +212,7 @@ func introspection<Entity: AnyObject & Sendable>(
{
confirmation4()
entity4 = $0
},
}
)

TestUtils.present(view: view)
Expand All @@ -232,7 +232,7 @@ func introspection<Entity: AnyObject & Sendable>(
#require(entity1, sourceLocation: sourceLocation),
#require(entity2, sourceLocation: sourceLocation),
#require(entity3, sourceLocation: sourceLocation),
#require(entity4, sourceLocation: sourceLocation),
#require(entity4, sourceLocation: sourceLocation)
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Tests/ViewTypes/ToggleWithButtonStyleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ struct ToggleWithButtonStyleTests {
Toggle("", isOn: .constant(true))
.toggleStyle(.button)
.introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15), customize: spy1)

Toggle("", isOn: .constant(false))
.toggleStyle(.button)
.introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15), customize: spy2)

Toggle("", isOn: .constant(true))
.toggleStyle(.button)
.introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15), customize: spy3)
Expand Down
6 changes: 3 additions & 3 deletions Tests/Tests/ViewTypes/VideoPlayerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ struct VideoPlayerTests {
#endif

@Test func introspect() async throws {
let videoURL1 = URL(string: "https://bit.ly/swswift#1")!
let videoURL2 = URL(string: "https://bit.ly/swswift#2")!
let videoURL3 = URL(string: "https://bit.ly/swswift#3")!
let videoURL1 = try #require(URL(string: "https://bit.ly/swswift#1"))
let videoURL2 = try #require(URL(string: "https://bit.ly/swswift#2"))
let videoURL3 = try #require(URL(string: "https://bit.ly/swswift#3"))

let (entity1, entity2, entity3) = try await introspection(of: PlatformVideoPlayer.self) { spy1, spy2, spy3 in
VStack {
Expand Down
10 changes: 5 additions & 5 deletions Tests/TestsHostApp/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import SwiftUI

@main
struct App: SwiftUI.App {
var body: some Scene {
WindowGroup {
EmptyView()
}
}
var body: some Scene {
WindowGroup {
EmptyView()
}
}
}
Loading