33 lines
788 B
Swift
33 lines
788 B
Swift
|
import Foundation
|
||
|
|
||
|
// Wrapper
|
||
|
@propertyWrapper
|
||
|
struct Storage<T> {
|
||
|
private let key: String
|
||
|
private let defaultValue: T
|
||
|
|
||
|
init(key: String, defaultValue: T) {
|
||
|
self.key = key
|
||
|
self.defaultValue = defaultValue
|
||
|
}
|
||
|
|
||
|
var wrappedValue: T {
|
||
|
get {
|
||
|
// Read value from UserDefaults
|
||
|
UserDefaults.standard.object(forKey: key) as? T ?? defaultValue
|
||
|
}
|
||
|
set {
|
||
|
// Set value to UserDefaults
|
||
|
UserDefaults.standard.set(newValue, forKey: key)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Storage
|
||
|
private let keyLocalizationSelected = "conversations.classic.user.defaults.localizationSelected"
|
||
|
|
||
|
enum UserSettings {
|
||
|
@Storage(key: keyLocalizationSelected, defaultValue: false)
|
||
|
static var localizationSelectedByUser: Bool
|
||
|
}
|