diff --git a/Package.resolved b/Package.resolved index 0570d1e..d18ce20 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,13 +1,22 @@ { - "originHash" : "5e69a65bc13b6866cc012a28d126dae3f03ac53e850f32034103be9b5d345cad", + "originHash" : "0176ca547be3045c0dad664f8065b6354d9a070d44592acf4b047888e61a7f21", "pins" : [ { "identity" : "alamofire", "kind" : "remoteSourceControl", "location" : "https://github.com/Alamofire/Alamofire.git", "state" : { - "revision" : "b2fa556e4e48cbf06cf8c63def138c98f4b811fa", - "version" : "5.8.0" + "revision" : "e16d3481f5ed35f0472cb93350085853d754913f", + "version" : "5.10.1" + } + }, + { + "identity" : "keychain-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/evgenyneu/keychain-swift.git", + "state" : { + "revision" : "5e1b02b6a9dac2a759a1d5dbc175c86bd192a608", + "version" : "24.0.0" } }, { @@ -15,8 +24,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/onevcat/Kingfisher.git", "state" : { - "revision" : "b6f62758f21a8c03cd64f4009c037cfa580a256e", - "version" : "7.9.1" + "revision" : "c0940e241945e6378c01fbd45fd3815579d47ef5", + "version" : "8.1.0" } }, { diff --git a/Package.swift b/Package.swift index ffc473d..41e8037 100644 --- a/Package.swift +++ b/Package.swift @@ -17,11 +17,12 @@ let package = Package( ) ], dependencies: [ - .package(url: "https://github.com/Alamofire/Alamofire.git", exact: "5.8.0"), - .package(url: "https://github.com/onevcat/Kingfisher.git", exact: "7.9.1"), - .package(url: "https://github.com/siteline/swiftui-introspect", from: "1.3.0"), - .package(url: "https://github.com/Swinject/Swinject.git", from: "2.9.1"), - .package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", from: "0.57.0") + .package(url: "https://github.com/Alamofire/Alamofire.git", exact: "5.10.1"), + .package(url: "https://github.com/onevcat/Kingfisher.git", exact: "8.1.0"), + .package(url: "https://github.com/siteline/swiftui-introspect", exact: "1.3.0"), + .package(url: "https://github.com/Swinject/Swinject.git", exact: "2.9.1"), + .package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", exact: "0.57.0"), + .package(url: "https://github.com/evgenyneu/keychain-swift.git", exact: "24.0.0") ], targets: [ .target( @@ -30,7 +31,8 @@ let package = Package( .product(name: "Alamofire", package: "Alamofire"), .product(name: "Kingfisher", package: "Kingfisher"), .product(name: "SwiftUIIntrospect", package: "swiftui-introspect"), - .product(name: "Swinject", package: "Swinject") + .product(name: "Swinject", package: "Swinject"), + .product(name: "KeychainSwift", package: "keychain-swift") ], plugins: [ .plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins") diff --git a/Sources/OEXFoundation/Extensions/DispatchQueue+App.swift b/Sources/OEXFoundation/Extensions/DispatchQueue+App.swift index f058e4f..7f3f765 100644 --- a/Sources/OEXFoundation/Extensions/DispatchQueue+App.swift +++ b/Sources/OEXFoundation/Extensions/DispatchQueue+App.swift @@ -7,8 +7,12 @@ import Foundation -public func doAfter(_ delay: TimeInterval? = nil, _ closure: @Sendable @escaping () -> Void) { - DispatchQueue.main.asyncAfter(deadline: .now() + (delay ?? 0), execute: closure) +@MainActor +public func doAfter(_ delay: TimeInterval? = nil, _ closure: @escaping () -> Void) { + Task { + try? await Task.sleep(for: .milliseconds((delay ?? 0) * 1000)) + closure() + } } public func dispatchQueueMain(_ closure: @Sendable @escaping () -> Void) { diff --git a/Sources/OEXFoundation/Network/API.swift b/Sources/OEXFoundation/Network/API.swift index 4fd7bbe..aef8969 100644 --- a/Sources/OEXFoundation/Network/API.swift +++ b/Sources/OEXFoundation/Network/API.swift @@ -9,10 +9,10 @@ import Foundation import Alamofire import WebKit -public final class API { +public final class API: Sendable { - let session: Alamofire.Session - let baseURL: URL + private let session: Alamofire.Session + private let baseURL: URL public init(session: Session, baseURL: URL) { self.session = session @@ -197,18 +197,16 @@ public enum APIError: Int, LocalizedError { } } -public struct CustomValidationError: LocalizedError { +public struct CustomValidationError: LocalizedError, Sendable { public let statusCode: Int - public let data: [String: Any]? + public let data: [String: any Any & Sendable]? - public init(statusCode: Int, data: [String: Any]?) { + public init(statusCode: Int, data: [String: any Any & Sendable]?) { self.statusCode = statusCode self.data = data } } -extension CustomValidationError: @unchecked Sendable {} - extension DataRequest { func validateResponse() -> Self { return validateStatusCode().validateContentType() @@ -223,7 +221,10 @@ extension DataRequest { if let data { if let dataString = String(data: data, encoding: .utf8) { if dataString.first == "{" && dataString.last == "}" { - let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] + let json = try? JSONSerialization.jsonObject( + with: data, + options: [] + ) as? [String: any Any & Sendable] return .failure(CustomValidationError(statusCode: response.statusCode, data: json)) } else { let reason: AFError.ResponseValidationFailureReason @@ -262,12 +263,12 @@ public struct CustomGetEncoding: ParameterEncoding { } extension Encodable { - func asDictionary() throws -> [String: Any] { + func asDictionary() throws -> [String: any Any & Sendable] { let data = try JSONEncoder().encode(self) guard let dictionary = try JSONSerialization.jsonObject( with: data, options: .fragmentsAllowed - ) as? [String: Any] else { + ) as? [String: any Any & Sendable] else { throw NSError( domain: "com.oexfoundation.error", code: 1, diff --git a/Sources/OEXFoundation/Network/HeadersRedirectHandler.swift b/Sources/OEXFoundation/Network/HeadersRedirectHandler.swift index 3653392..dc9a708 100644 --- a/Sources/OEXFoundation/Network/HeadersRedirectHandler.swift +++ b/Sources/OEXFoundation/Network/HeadersRedirectHandler.swift @@ -8,7 +8,7 @@ import Foundation import Alamofire -public class HeadersRedirectHandler: RedirectHandler { +public final class HeadersRedirectHandler: RedirectHandler { public init() { } diff --git a/Sources/OEXFoundation/Network/NetworkLogger.swift b/Sources/OEXFoundation/Network/NetworkLogger.swift index 7335be2..5b56eec 100644 --- a/Sources/OEXFoundation/Network/NetworkLogger.swift +++ b/Sources/OEXFoundation/Network/NetworkLogger.swift @@ -8,7 +8,7 @@ import Alamofire import Foundation -public class NetworkLogger: EventMonitor { +public final class NetworkLogger: EventMonitor { public let queue = DispatchQueue(label: "com.raccoongang.networklogger")