Skip to content

Commit

Permalink
Swift 6 Migration (#71)
Browse files Browse the repository at this point in the history
* update dependencies

* migrate to swift 6

---------

Co-authored-by: Oguz Yuksel <[email protected]>
  • Loading branch information
OguzYuuksel and Oguz Yuksel authored Sep 26, 2024
1 parent 2d16f0d commit 9126dcb
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 30 deletions.
14 changes: 7 additions & 7 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/teufelaudio/FoundationExtensions.git",
"state" : {
"revision" : "c441f8fa10ee6c93ce4d4d3939a8bd683987e48f",
"version" : "0.6.2"
"revision" : "f664fd15bf661193b2595bdcf8d7fc6eadb94fe2",
"version" : "1.0.0"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing.git",
"state" : {
"revision" : "8e68404f641300bfd0e37d478683bb275926760c",
"version" : "1.15.2"
"revision" : "7b0bbbae90c41f848f90ac7b4df6c4f50068256d",
"version" : "1.17.5"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
"revision" : "0687f71944021d616d34d922343dcef086855920",
"version" : "600.0.1"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:6.0

import PackageDescription

Expand All @@ -12,7 +12,7 @@ let package = Package(

],
dependencies: [
.package(url: "https://github.com/teufelaudio/FoundationExtensions.git", from: "0.5.0"),
.package(url: "https://github.com/teufelaudio/FoundationExtensions.git", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing.git", from: "1.11.0"),
],
targets: [
Expand Down
21 changes: 10 additions & 11 deletions Sources/SnapshotTestingExtensions/SnapshotTestBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ import SnapshotTesting
import SwiftUI
import XCTest

@MainActor
open class SnapshotTestBase: XCTestCase {
public var allowAnimations: Bool = false

override open func setUp() {
super.setUp()
UIView.setAnimationsEnabled(allowAnimations)
}

open var defaultDevices: [(name: String, device: ViewImageConfig)] {
[
("SE", .iPhoneSe),
Expand All @@ -22,12 +16,13 @@ open class SnapshotTestBase: XCTestCase {
("iPadPro", .iPadPro12_9(.portrait))
]
}

open func assertSnapshotDevices<V: View>(
_ view: V,
devices: [(name: String, device: ViewImageConfig)]? = nil,
style: [UIUserInterfaceStyle] = [.unspecified],
imageDiffPrecision: Float = 1.0,
allowAnimations: Bool = false,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line
Expand All @@ -38,18 +33,20 @@ open class SnapshotTestBase: XCTestCase {
as: .image(on: config.device, precision: imageDiffPrecision),
style: style,
config: config,
allowAnimations: allowAnimations,
file: file,
testName: testName,
line: line
)
}
}

open func assertSnapshotDevices<V: View>(
_ view: V,
devices: [(name: String, device: ViewImageConfig)]? = nil,
style: [UIUserInterfaceStyle] = [.unspecified],
imageDiffPrecision: Float = 1.0,
allowAnimations: Bool = false,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line,
Expand All @@ -65,19 +62,21 @@ open class SnapshotTestBase: XCTestCase {
// called to trigger rendering e.g. for AsyncImage
vc.viewDidAppear(false)
},
allowAnimations: allowAnimations,
file: file,
testName: testName,
line: line
)
}
}

private func assertSnapshotDevices<V: View>(
_ view: V,
as snapshotting: Snapshotting<UIViewController, UIImage>,
style: [UIUserInterfaceStyle] = [.unspecified],
config: (name: String, device: ViewImageConfig),
preAssertionInterceptor: ((UIViewController) -> Void)? = nil,
allowAnimations: Bool,
file: StaticString,
testName: String,
line: UInt
Expand All @@ -101,7 +100,7 @@ open class SnapshotTestBase: XCTestCase {
}

assertSnapshot(
matching: vc,
of: vc,
as: snapshotting,
file: file,
testName: "\(testName)-\(config.name)\(suffix)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public struct PageControlView: UIViewRepresentable {

/// Coordinator for this PageIndicator. Used only to update the source binding when a user taps on a
/// page "dot" itself.
@MainActor
public class Coordinator: NSObject {
fileprivate var control: PageControlView

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ extension PageView {
/// is called once the view struct is recreated. It is responsible for updating the `UIPageViewController`
/// of the new configuration, the `PageView` also needs to update this `PageViewCoordinator` in
/// based on the current configuration of the NEWLY CREATED `PageView`.
@MainActor
public final class PageViewCoordinator {
fileprivate var parent: PageView

Expand Down Expand Up @@ -222,7 +223,7 @@ private final class PageControllerDataSource: NSObject, UIPageViewControllerData
}
}

private class IdentifiableHostingController<ID: Hashable, Content: View>: UIHostingController<Content>, Identifiable {
private class IdentifiableHostingController<ID: Hashable, Content: View>: UIHostingController<Content> {
var id: ID

init(id: ID, content: Content) {
Expand Down
6 changes: 3 additions & 3 deletions Sources/UIExtensions/Extensions/Binding+Debug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ extension Binding {
/// - onSet: Closure to execute whenever the value is changed. This closure is passed the old
/// value and the new value respectively before the value is changed.
/// - Returns: Binding with same types, can be chained.
public func debug(onGet: ((Value) -> Void)? = nil,
onSet: ((Value, Value) -> Void)? = nil)
-> Self {
public func debug(onGet: (@Sendable (Value) -> Void)? = nil,
onSet: (@Sendable (Value, Value) -> Void)? = nil)
-> Self where Value: Sendable {
.init {
let currentValue = self.wrappedValue
onGet?(currentValue)
Expand Down
5 changes: 3 additions & 2 deletions Sources/UIExtensions/Extensions/Binding+Optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extension Binding {
///
/// You can optionally provide a closure to be called when the inner component sets the wrapped
/// value no nil, so your parent control can act on that accordingly.
public func toOptional(onSetToNil: @escaping () -> Void = { }) -> Binding<Value?> {
public func toOptional(onSetToNil: @escaping @Sendable () -> Void = { }) -> Binding<Value?> where Value: Sendable {
Binding<Value?>(
get: { self.wrappedValue },
set: { newValue in
Expand All @@ -27,10 +27,11 @@ extension Binding {
/// Transforms a `Binding<Optional<Value>>` in a `Binding<Value>`. This is useful when your
/// internal binding requires a non-nil value, but your parent control only offers binding
/// to an Optional type. You must provide a default fallback for when reading a nil value.
public func toNonOptional<V>(default fallback: V) -> Binding<V> where Value == V? {
public func toNonOptional<V: Sendable>(default fallback: V) -> Binding<V> where Value == V? {
Binding<V>(
get: { self.wrappedValue ?? fallback },
set: { self.wrappedValue = $0 }
)
}
}

9 changes: 5 additions & 4 deletions Sources/UIExtensions/Helpers/ApplicationOpener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import Foundation
import UIKit

@objc
@MainActor
public protocol ApplicationOpener {
var openSettingsURL: String { get }
func canOpenURL(_ url: URL) -> Bool
nonisolated var openSettingsURL: String { get }
nonisolated func canOpenURL(_ url: URL) -> Bool
@available(iOSApplicationExtension, unavailable)
@objc(openURL:options:completionHandler:)
func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any], completionHandler completion: ((Bool) -> Void)?)
func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any], completionHandler completion: (@MainActor @Sendable (Bool) -> Void)?)
}

@available(iOSApplicationExtension, unavailable)
extension UIApplication: ApplicationOpener {
public var openSettingsURL: String {
nonisolated public var openSettingsURL: String {
Self.openSettingsURLString
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Foundation
import SwiftUI

extension AnyTransition {
@MainActor
public static func rectangular(anchor: AnimationAnchor) -> AnyTransition {
AnyTransition.modifier(
active: ShapeClipModifier(shape: RectangularShape(pct: 1, anchor: anchor)),
Expand Down

0 comments on commit 9126dcb

Please sign in to comment.