Switch from deprecated NSSecureCoding API (#132)

Fixes #131
This commit is contained in:
Sindre Sorhus 2023-04-07 11:49:00 +09:00 committed by GitHub
parent a09d7c8957
commit 8584d1d6ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 7 deletions

View File

@ -50,7 +50,7 @@ extension Defaults {
This exists to avoid compiler ambiguity. This exists to avoid compiler ambiguity.
*/ */
extension Defaults { extension Defaults {
public struct CodableNSSecureCodingBridge<Value: Codable & NSSecureCoding>: CodableBridge {} public struct CodableNSSecureCodingBridge<Value: Codable & NSSecureCoding & NSObject>: CodableBridge {}
} }
extension Defaults { extension Defaults {
@ -79,7 +79,7 @@ extension Defaults {
} }
extension Defaults { extension Defaults {
public struct NSSecureCodingBridge<Value: NSSecureCoding>: Bridge { public struct NSSecureCodingBridge<Value: NSSecureCoding & NSObject>: Bridge {
public typealias Value = Value public typealias Value = Value
public typealias Serializable = Data public typealias Serializable = Data
@ -97,7 +97,7 @@ extension Defaults {
} }
do { do {
return try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(object) as? Value return try NSKeyedUnarchiver.unarchivedObject(ofClass: Value.self, from: object)
} catch { } catch {
print(error) print(error)
return nil return nil

View File

@ -85,11 +85,11 @@ extension Defaults.Serializable where Self: Codable {
public static var bridge: Defaults.TopLevelCodableBridge<Self> { Defaults.TopLevelCodableBridge() } public static var bridge: Defaults.TopLevelCodableBridge<Self> { Defaults.TopLevelCodableBridge() }
} }
extension Defaults.Serializable where Self: Codable & NSSecureCoding { extension Defaults.Serializable where Self: Codable & NSSecureCoding & NSObject {
public static var bridge: Defaults.CodableNSSecureCodingBridge<Self> { Defaults.CodableNSSecureCodingBridge() } public static var bridge: Defaults.CodableNSSecureCodingBridge<Self> { Defaults.CodableNSSecureCodingBridge() }
} }
extension Defaults.Serializable where Self: Codable & NSSecureCoding & Defaults.PreferNSSecureCoding { extension Defaults.Serializable where Self: Codable & NSSecureCoding & NSObject & Defaults.PreferNSSecureCoding {
public static var bridge: Defaults.NSSecureCodingBridge<Self> { Defaults.NSSecureCodingBridge() } public static var bridge: Defaults.NSSecureCodingBridge<Self> { Defaults.NSSecureCodingBridge() }
} }
@ -104,7 +104,7 @@ extension Defaults.Serializable where Self: Codable & RawRepresentable & Default
extension Defaults.Serializable where Self: RawRepresentable { extension Defaults.Serializable where Self: RawRepresentable {
public static var bridge: Defaults.RawRepresentableBridge<Self> { Defaults.RawRepresentableBridge() } public static var bridge: Defaults.RawRepresentableBridge<Self> { Defaults.RawRepresentableBridge() }
} }
extension Defaults.Serializable where Self: NSSecureCoding { extension Defaults.Serializable where Self: NSSecureCoding & NSObject {
public static var bridge: Defaults.NSSecureCodingBridge<Self> { Defaults.NSSecureCodingBridge() } public static var bridge: Defaults.NSSecureCodingBridge<Self> { Defaults.NSSecureCodingBridge() }
} }

View File

@ -41,7 +41,7 @@ public protocol _DefaultsSetAlgebraSerializable: SetAlgebra, Defaults.Serializab
public protocol _DefaultsCodableBridge: Defaults.Bridge where Serializable == String, Value: Codable {} public protocol _DefaultsCodableBridge: Defaults.Bridge where Serializable == String, Value: Codable {}
public protocol _DefaultsPreferRawRepresentable: RawRepresentable {} public protocol _DefaultsPreferRawRepresentable: RawRepresentable {}
public protocol _DefaultsPreferNSSecureCoding: NSSecureCoding {} public protocol _DefaultsPreferNSSecureCoding: NSObject, NSSecureCoding {}
// Essential properties for serializing and deserializing `ClosedRange` and `Range`. // Essential properties for serializing and deserializing `ClosedRange` and `Range`.
public protocol _DefaultsRange { public protocol _DefaultsRange {