parent
5f16cefebe
commit
8a6e4a96fd
|
@ -1,13 +1,13 @@
|
||||||
// swift-tools-version:5.4
|
// swift-tools-version:5.5
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "Defaults",
|
name: "Defaults",
|
||||||
platforms: [
|
platforms: [
|
||||||
.macOS(.v10_12),
|
.macOS(.v10_13),
|
||||||
.iOS(.v10),
|
.iOS(.v12),
|
||||||
.tvOS(.v10),
|
.tvOS(.v12),
|
||||||
.watchOS(.v3)
|
.watchOS(.v5)
|
||||||
],
|
],
|
||||||
products: [
|
products: [
|
||||||
.library(
|
.library(
|
||||||
|
|
|
@ -88,16 +88,7 @@ extension Defaults {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version below macOS 10.13 and iOS 11.0 does not support `archivedData(withRootObject:requiringSecureCoding:)`.
|
return try? NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: true)
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func deserialize(_ object: Serializable?) -> Value? {
|
public func deserialize(_ object: Serializable?) -> Value? {
|
||||||
|
|
|
@ -3,7 +3,6 @@ import CoreData
|
||||||
import Defaults
|
import Defaults
|
||||||
import XCTest
|
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 {
|
private final class ExamplePersistentHistory: NSPersistentHistoryToken, Defaults.Serializable {
|
||||||
let value: String
|
let value: String
|
||||||
|
|
||||||
|
@ -25,16 +24,14 @@ private final class ExamplePersistentHistory: NSPersistentHistoryToken, Defaults
|
||||||
}
|
}
|
||||||
|
|
||||||
// NSSecureCoding
|
// 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 {
|
extension Defaults.Keys {
|
||||||
fileprivate static let persistentHistory = Key<ExamplePersistentHistory>("persistentHistory", default: persistentHistoryValue)
|
fileprivate static let persistentHistory = Key<ExamplePersistentHistory>("persistentHistory", default: persistentHistoryValue)
|
||||||
fileprivate static let persistentHistoryArray = Key<[ExamplePersistentHistory]>("array_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])
|
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 {
|
final class DefaultsNSSecureCodingTests: XCTestCase {
|
||||||
override func setUp() {
|
override func setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
|
@ -313,7 +310,6 @@ final class DefaultsNSSecureCodingTests: XCTestCase {
|
||||||
waitForExpectations(timeout: 10)
|
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() {
|
func testObserveMultipleNSSecureKeys() {
|
||||||
let key1 = Defaults.Key<ExamplePersistentHistory>("observeNSSecureCodingKey1", default: ExamplePersistentHistory(value: "TestValue"))
|
let key1 = Defaults.Key<ExamplePersistentHistory>("observeNSSecureCodingKey1", default: ExamplePersistentHistory(value: "TestValue"))
|
||||||
let key2 = Defaults.Key<ExamplePersistentHistory>("observeNSSecureCodingKey2", default: ExamplePersistentHistory(value: "TestValue"))
|
let key2 = Defaults.Key<ExamplePersistentHistory>("observeNSSecureCodingKey2", default: ExamplePersistentHistory(value: "TestValue"))
|
||||||
|
|
Loading…
Reference in New Issue