Remove `DefaultsBaseKey` (#123)
This commit is contained in:
parent
fbc67fd179
commit
35943225a0
|
@ -1,22 +1,7 @@
|
||||||
// MIT License © Sindre Sorhus
|
// MIT License © Sindre Sorhus
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public protocol DefaultsBaseKey {
|
|
||||||
var name: String { get }
|
|
||||||
var suite: UserDefaults { get }
|
|
||||||
}
|
|
||||||
|
|
||||||
extension DefaultsBaseKey {
|
|
||||||
/**
|
|
||||||
Reset the item back to its default value.
|
|
||||||
*/
|
|
||||||
public func reset() {
|
|
||||||
suite.removeObject(forKey: name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Defaults {
|
public enum Defaults {
|
||||||
public typealias BaseKey = DefaultsBaseKey
|
|
||||||
public typealias Keys = AnyKey
|
public typealias Keys = AnyKey
|
||||||
public typealias Serializable = DefaultsSerializable
|
public typealias Serializable = DefaultsSerializable
|
||||||
public typealias CollectionSerializable = DefaultsCollectionSerializable
|
public typealias CollectionSerializable = DefaultsCollectionSerializable
|
||||||
|
@ -28,7 +13,7 @@ public enum Defaults {
|
||||||
typealias CodableBridge = DefaultsCodableBridge
|
typealias CodableBridge = DefaultsCodableBridge
|
||||||
|
|
||||||
// We cannot use `Key` as the container for keys because of "Static stored properties not supported in generic types".
|
// We cannot use `Key` as the container for keys because of "Static stored properties not supported in generic types".
|
||||||
public class AnyKey: BaseKey {
|
public class AnyKey {
|
||||||
public typealias Key = Defaults.Key
|
public typealias Key = Defaults.Key
|
||||||
|
|
||||||
public let name: String
|
public let name: String
|
||||||
|
@ -38,6 +23,13 @@ public enum Defaults {
|
||||||
self.name = name
|
self.name = name
|
||||||
self.suite = suite
|
self.suite = suite
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Reset the item back to its default value.
|
||||||
|
*/
|
||||||
|
public func reset() {
|
||||||
|
suite.removeObject(forKey: name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class Key<Value: Serializable>: AnyKey {
|
public final class Key<Value: Serializable>: AnyKey {
|
||||||
|
|
Loading…
Reference in New Issue