Skip to content

Commit

Permalink
Switch from deprecated NSSecureCoding API (#132)
Browse files Browse the repository at this point in the history
Fixes #131
  • Loading branch information
sindresorhus authored Apr 7, 2023
1 parent a09d7c8 commit 8584d1d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Sources/Defaults/Defaults+Bridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extension Defaults {
This exists to avoid compiler ambiguity.
*/
extension Defaults {
public struct CodableNSSecureCodingBridge<Value: Codable & NSSecureCoding>: CodableBridge {}
public struct CodableNSSecureCodingBridge<Value: Codable & NSSecureCoding & NSObject>: CodableBridge {}
}

extension Defaults {
Expand Down Expand Up @@ -79,7 +79,7 @@ extension Defaults {
}

extension Defaults {
public struct NSSecureCodingBridge<Value: NSSecureCoding>: Bridge {
public struct NSSecureCodingBridge<Value: NSSecureCoding & NSObject>: Bridge {
public typealias Value = Value
public typealias Serializable = Data

Expand All @@ -97,7 +97,7 @@ extension Defaults {
}

do {
return try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(object) as? Value
return try NSKeyedUnarchiver.unarchivedObject(ofClass: Value.self, from: object)
} catch {
print(error)
return nil
Expand Down
6 changes: 3 additions & 3 deletions Sources/Defaults/Defaults+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ extension Defaults.Serializable where Self: Codable {
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() }
}

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() }
}

Expand All @@ -104,7 +104,7 @@ extension Defaults.Serializable where Self: Codable & RawRepresentable & Default
extension Defaults.Serializable where Self: RawRepresentable {
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() }
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Defaults/Defaults+Protocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public protocol _DefaultsSetAlgebraSerializable: SetAlgebra, Defaults.Serializab
public protocol _DefaultsCodableBridge: Defaults.Bridge where Serializable == String, Value: Codable {}

public protocol _DefaultsPreferRawRepresentable: RawRepresentable {}
public protocol _DefaultsPreferNSSecureCoding: NSSecureCoding {}
public protocol _DefaultsPreferNSSecureCoding: NSObject, NSSecureCoding {}

// Essential properties for serializing and deserializing `ClosedRange` and `Range`.
public protocol _DefaultsRange {
Expand Down

0 comments on commit 8584d1d

Please sign in to comment.