From 1c30f90abe4118773e89b819d6b5db91432a81a5 Mon Sep 17 00:00:00 2001 From: stackotter Date: Fri, 18 Jul 2025 14:20:54 +1000 Subject: [PATCH] Drop macOS requirement to 10.15 with availability annotations --- Package.swift | 4 ++-- Sources/ErrorKit/Helpers/Logger+ErrorKit.swift | 1 + Sources/ErrorKit/Helpers/String+ErrorKit.swift | 14 ++++++++------ Sources/ErrorKit/Logging/ErrorKit+OSLog.swift | 4 ++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Package.swift b/Package.swift index 93f6e0f..2252ba8 100644 --- a/Package.swift +++ b/Package.swift @@ -1,10 +1,10 @@ -// swift-tools-version: 6.0 +// swift-tools-version:5.9 import PackageDescription let package = Package( name: "ErrorKit", defaultLocalization: "en", - platforms: [.macOS(.v13), .iOS(.v16), .tvOS(.v16), .watchOS(.v9), .macCatalyst(.v16)], + platforms: [.macOS(.v10_15), .iOS(.v16), .tvOS(.v16), .watchOS(.v9), .macCatalyst(.v16)], products: [.library(name: "ErrorKit", targets: ["ErrorKit"])], dependencies: [ // CryptoKit is not available on Linux, so we need Swift Crypto diff --git a/Sources/ErrorKit/Helpers/Logger+ErrorKit.swift b/Sources/ErrorKit/Helpers/Logger+ErrorKit.swift index 17cee25..918eb43 100644 --- a/Sources/ErrorKit/Helpers/Logger+ErrorKit.swift +++ b/Sources/ErrorKit/Helpers/Logger+ErrorKit.swift @@ -1,6 +1,7 @@ #if canImport(OSLog) import OSLog +@available(macOS 11, *) extension Logger { /// Logs a debug message with complete error chain description /// diff --git a/Sources/ErrorKit/Helpers/String+ErrorKit.swift b/Sources/ErrorKit/Helpers/String+ErrorKit.swift index 1dc48b2..2a02bbe 100644 --- a/Sources/ErrorKit/Helpers/String+ErrorKit.swift +++ b/Sources/ErrorKit/Helpers/String+ErrorKit.swift @@ -2,12 +2,14 @@ import Foundation extension String { #if canImport(CryptoKit) - // On Apple platforms, use the modern localization API with Bundle.module - static func localized(key: StaticString, defaultValue: String.LocalizationValue) -> String { - return String( - localized: key, - defaultValue: defaultValue, - bundle: Bundle.module + // On Apple platforms, use the old localization API with Bundle.module + static func localized(key: StaticString, defaultValue: String) -> String { + return NSLocalizedString( + key.description, + tableName: nil, + bundle: Bundle.module, + value: defaultValue, + comment: defaultValue ) } #else diff --git a/Sources/ErrorKit/Logging/ErrorKit+OSLog.swift b/Sources/ErrorKit/Logging/ErrorKit+OSLog.swift index 7bb4c08..65699ca 100644 --- a/Sources/ErrorKit/Logging/ErrorKit+OSLog.swift +++ b/Sources/ErrorKit/Logging/ErrorKit+OSLog.swift @@ -60,6 +60,7 @@ extension ErrorKit { /// ``` /// /// - See Also: ``exportLogFile(ofLast:minLevel:)`` for when you need a URL with the log content written to a text file + @available(macOS 13, *) public static func loggedData(ofLast duration: Duration, minLevel: OSLogEntryLog.Level = .notice) throws -> Data { let logStore = try OSLogStore(scope: .currentProcessIdentifier) @@ -86,6 +87,7 @@ extension ErrorKit { /// - Throws: Errors if log store access fails or if writing to the file fails /// /// - See Also: ``loggedData(ofLast:minLevel:)`` for when you need the log content as Data directly + @available(macOS 13, *) public static func exportLogFile(ofLast duration: Duration, minLevel: OSLogEntryLog.Level = .notice) throws -> URL { let logData = try loggedData(ofLast: duration, minLevel: minLevel) @@ -140,6 +142,7 @@ extension ErrorKit { /// attachments: [logAttachment] /// ) /// ``` + @available(macOS 13, *) public static func logAttachment( ofLast duration: Duration, minLevel: OSLogEntryLog.Level = .notice, @@ -157,6 +160,7 @@ extension ErrorKit { } } +@available(macOS 13, *) extension Duration { /// Returns the duration as a `TimeInterval`. ///