metatext/Shared/Model/Defaults.swift

25 lines
539 B
Swift
Raw Normal View History

2020-08-02 22:23:01 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
2020-08-06 06:45:57 +00:00
class Defaults {
2020-08-02 22:23:01 +00:00
private let userDefaults: UserDefaults
init(userDefaults: UserDefaults) {
self.userDefaults = userDefaults
}
}
2020-08-06 06:45:57 +00:00
extension Defaults {
2020-08-02 22:23:01 +00:00
enum Item: String {
case recentIdentityID = "recent-identity-id"
}
}
2020-08-06 06:45:57 +00:00
extension Defaults {
subscript<T>(index: Defaults.Item) -> T? {
2020-08-02 22:23:01 +00:00
get { userDefaults.value(forKey: index.rawValue) as? T }
set { userDefaults.set(newValue, forKey: index.rawValue) }
}
}