From 8a6e4a96fd38504a05903d136c85634b65fd7c4d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 12 Oct 2021 13:45:07 +0700 Subject: [PATCH] Require macOS 10.13, iOS 12, tvOS 12, watchOS 5 Fixes #81 --- Package.swift | 10 +++++----- Sources/Defaults/Defaults+Bridge.swift | 11 +---------- Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift | 6 +----- readme.md | 8 ++++---- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/Package.swift b/Package.swift index b88d71a..a8f7f60 100644 --- a/Package.swift +++ b/Package.swift @@ -1,13 +1,13 @@ -// swift-tools-version:5.4 +// swift-tools-version:5.5 import PackageDescription let package = Package( name: "Defaults", platforms: [ - .macOS(.v10_12), - .iOS(.v10), - .tvOS(.v10), - .watchOS(.v3) + .macOS(.v10_13), + .iOS(.v12), + .tvOS(.v12), + .watchOS(.v5) ], products: [ .library( diff --git a/Sources/Defaults/Defaults+Bridge.swift b/Sources/Defaults/Defaults+Bridge.swift index fbc1277..95d6635 100644 --- a/Sources/Defaults/Defaults+Bridge.swift +++ b/Sources/Defaults/Defaults+Bridge.swift @@ -88,16 +88,7 @@ extension Defaults { return nil } - // Version below macOS 10.13 and iOS 11.0 does not support `archivedData(withRootObject:requiringSecureCoding:)`. - // We need to set `requiresSecureCoding` ourselves. - if #available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) { - return try? NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: true) - } else { - let keyedArchiver = NSKeyedArchiver() - keyedArchiver.requiresSecureCoding = true - keyedArchiver.encode(object, forKey: NSKeyedArchiveRootObjectKey) - return keyedArchiver.encodedData - } + return try? NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: true) } public func deserialize(_ object: Serializable?) -> Value? { diff --git a/Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift b/Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift index 2245c98..3658771 100644 --- a/Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift +++ b/Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift @@ -3,7 +3,6 @@ import CoreData import Defaults import XCTest -@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) private final class ExamplePersistentHistory: NSPersistentHistoryToken, Defaults.Serializable { let value: String @@ -25,16 +24,14 @@ private final class ExamplePersistentHistory: NSPersistentHistoryToken, Defaults } // NSSecureCoding -@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) private let persistentHistoryValue = ExamplePersistentHistory(value: "ExampleToken") +private let persistentHistoryValue = ExamplePersistentHistory(value: "ExampleToken") -@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) extension Defaults.Keys { fileprivate static let persistentHistory = Key("persistentHistory", default: persistentHistoryValue) fileprivate static let persistentHistoryArray = Key<[ExamplePersistentHistory]>("array_persistentHistory", default: [persistentHistoryValue]) fileprivate static let persistentHistoryDictionary = Key<[String: ExamplePersistentHistory]>("dictionary_persistentHistory", default: ["0": persistentHistoryValue]) } -@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) final class DefaultsNSSecureCodingTests: XCTestCase { override func setUp() { super.setUp() @@ -313,7 +310,6 @@ final class DefaultsNSSecureCodingTests: XCTestCase { waitForExpectations(timeout: 10) } - @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) func testObserveMultipleNSSecureKeys() { let key1 = Defaults.Key("observeNSSecureCodingKey1", default: ExamplePersistentHistory(value: "TestValue")) let key2 = Defaults.Key("observeNSSecureCodingKey2", default: ExamplePersistentHistory(value: "TestValue")) diff --git a/readme.md b/readme.md index 453a78a..0686b0c 100644 --- a/readme.md +++ b/readme.md @@ -23,10 +23,10 @@ For a real-world example, see the [Plash app](https://github.com/sindresorhus/Pl ## Compatibility -- macOS 10.12+ -- iOS 10+ -- tvOS 10+ -- watchOS 3+ +- macOS 10.13+ +- iOS 12+ +- tvOS 12+ +- watchOS 5+