From 1012fbee86ea55c28798eaa0b0f27276e4e2eaff Mon Sep 17 00:00:00 2001 From: d-date Date: Thu, 21 Mar 2024 00:50:42 +0000 Subject: [PATCH] [ci skip] Run swift-format --- MyLibrary/Package.swift | 2 +- .../Sources/DependencyExtra/Safari.swift | 120 +++++++++--------- .../Sources/GuidanceFeature/Guidance.swift | 2 +- .../Sources/ScheduleFeature/Detail.swift | 2 +- .../Sources/SponsorFeature/Sponsors.swift | 2 +- .../Sources/trySwiftFeature/Profile.swift | 2 +- 6 files changed, 65 insertions(+), 65 deletions(-) diff --git a/MyLibrary/Package.swift b/MyLibrary/Package.swift index 0d1b107..404847f 100644 --- a/MyLibrary/Package.swift +++ b/MyLibrary/Package.swift @@ -43,7 +43,7 @@ let package = Package( .target( name: "DependencyExtra", dependencies: [ - .product(name: "Dependencies", package: "swift-dependencies"), + .product(name: "Dependencies", package: "swift-dependencies") ] ), .target( diff --git a/MyLibrary/Sources/DependencyExtra/Safari.swift b/MyLibrary/Sources/DependencyExtra/Safari.swift index e916a8e..288cd60 100644 --- a/MyLibrary/Sources/DependencyExtra/Safari.swift +++ b/MyLibrary/Sources/DependencyExtra/Safari.swift @@ -1,82 +1,82 @@ import Dependencies #if canImport(SafariServices) && canImport(SwiftUI) -import SafariServices -import SwiftUI + import SafariServices + import SwiftUI -extension DependencyValues { - /// A dependency that opens a URL in SFSafariViewController. - /// - /// In iOS, use SFSafariViewController in UIKit context. Otherwise use openURL in environment values - /// - /// - SeeAlso: https://sarunw.com/posts/sfsafariviewcontroller-in-swiftui/ - @available(iOS 15, macOS 11, tvOS 14, watchOS 7, *) - public var safari: SafariEffect { - get { self[SafariKey.self] } - set { self[SafariKey.self] = newValue } + extension DependencyValues { + /// A dependency that opens a URL in SFSafariViewController. + /// + /// In iOS, use SFSafariViewController in UIKit context. Otherwise use openURL in environment values + /// + /// - SeeAlso: https://sarunw.com/posts/sfsafariviewcontroller-in-swiftui/ + @available(iOS 15, macOS 11, tvOS 14, watchOS 7, *) + public var safari: SafariEffect { + get { self[SafariKey.self] } + set { self[SafariKey.self] = newValue } + } } -} -@available(iOS 15, macOS 11, tvOS 14, watchOS 7, *) -private enum SafariKey: DependencyKey { - static let liveValue = SafariEffect { url in - let stream = AsyncStream { continuation in - let task = Task { @MainActor in -#if os(iOS) - let vc = SFSafariViewController(url: url) - UIApplication.shared.firstKeyWindow?.rootViewController?.present(vc, animated: true) - continuation.yield(true) - continuation.finish() -#else - EnvironmentValues().openURL(url) - continuation.yield(true) - continuation.finish() -#endif - } - continuation.onTermination = { @Sendable _ in - task.cancel() + @available(iOS 15, macOS 11, tvOS 14, watchOS 7, *) + private enum SafariKey: DependencyKey { + static let liveValue = SafariEffect { url in + let stream = AsyncStream { continuation in + let task = Task { @MainActor in + #if os(iOS) + let vc = SFSafariViewController(url: url) + UIApplication.shared.firstKeyWindow?.rootViewController?.present(vc, animated: true) + continuation.yield(true) + continuation.finish() + #else + EnvironmentValues().openURL(url) + continuation.yield(true) + continuation.finish() + #endif + } + continuation.onTermination = { @Sendable _ in + task.cancel() + } } + return await stream.first(where: { _ in true }) ?? false + } + static let testValue = SafariEffect { _ in + XCTFail(#"Unimplemented: @Dependency(\.safari)"#) + return false } - return await stream.first(where: { _ in true }) ?? false - } - static let testValue = SafariEffect { _ in - XCTFail(#"Unimplemented: @Dependency(\.safari)"#) - return false } -} -public struct SafariEffect: Sendable { - private let handler: @Sendable (URL) async -> Bool + public struct SafariEffect: Sendable { + private let handler: @Sendable (URL) async -> Bool - public init(handler: @escaping @Sendable (URL) async -> Bool) { - self.handler = handler - } + public init(handler: @escaping @Sendable (URL) async -> Bool) { + self.handler = handler + } - @available(watchOS, unavailable) - @discardableResult - public func callAsFunction(_ url: URL) async -> Bool { - await self.handler(url) - } + @available(watchOS, unavailable) + @discardableResult + public func callAsFunction(_ url: URL) async -> Bool { + await self.handler(url) + } - @_disfavoredOverload - public func callAsFunction(_ url: URL) async { - _ = await self.handler(url) + @_disfavoredOverload + public func callAsFunction(_ url: URL) async { + _ = await self.handler(url) + } } -} #endif #if canImport(UIKit) -import UIKit + import UIKit -extension UIApplication { - @available(iOS 15.0, *) - var firstKeyWindow: UIWindow? { - return UIApplication.shared.connectedScenes - .compactMap { $0 as? UIWindowScene } - .filter { $0.activationState == .foregroundActive } - .first?.keyWindow + extension UIApplication { + @available(iOS 15.0, *) + var firstKeyWindow: UIWindow? { + return UIApplication.shared.connectedScenes + .compactMap { $0 as? UIWindowScene } + .filter { $0.activationState == .foregroundActive } + .first?.keyWindow + } } -} #endif diff --git a/MyLibrary/Sources/GuidanceFeature/Guidance.swift b/MyLibrary/Sources/GuidanceFeature/Guidance.swift index 2ae9f79..fd275ca 100644 --- a/MyLibrary/Sources/GuidanceFeature/Guidance.swift +++ b/MyLibrary/Sources/GuidanceFeature/Guidance.swift @@ -1,9 +1,9 @@ import ComposableArchitecture import CoreLocation +import DependencyExtra import Foundation import MapKit import MapKitClient -import DependencyExtra import SwiftUI @Reducer diff --git a/MyLibrary/Sources/ScheduleFeature/Detail.swift b/MyLibrary/Sources/ScheduleFeature/Detail.swift index 74270e2..b472f30 100644 --- a/MyLibrary/Sources/ScheduleFeature/Detail.swift +++ b/MyLibrary/Sources/ScheduleFeature/Detail.swift @@ -1,6 +1,6 @@ import ComposableArchitecture -import Foundation import DependencyExtra +import Foundation import SharedModels import SwiftUI diff --git a/MyLibrary/Sources/SponsorFeature/Sponsors.swift b/MyLibrary/Sources/SponsorFeature/Sponsors.swift index 8ce0b72..568a89e 100644 --- a/MyLibrary/Sources/SponsorFeature/Sponsors.swift +++ b/MyLibrary/Sources/SponsorFeature/Sponsors.swift @@ -1,7 +1,7 @@ import ComposableArchitecture import DataClient -import Foundation import DependencyExtra +import Foundation import SharedModels import SwiftUI diff --git a/MyLibrary/Sources/trySwiftFeature/Profile.swift b/MyLibrary/Sources/trySwiftFeature/Profile.swift index 49fe8db..3972dee 100644 --- a/MyLibrary/Sources/trySwiftFeature/Profile.swift +++ b/MyLibrary/Sources/trySwiftFeature/Profile.swift @@ -1,6 +1,6 @@ import ComposableArchitecture -import Foundation import DependencyExtra +import Foundation import SharedModels import SwiftUI