37 lines
948 B
Swift
37 lines
948 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 kOmemoDeviceId = "conversations.classic.user.defaults.omemoDeviceId"
|
|
private let kSecureChatsByDefault = "conversations.classic.user.defaults.secureChatsByDefault"
|
|
|
|
enum UserSettings {
|
|
@Storage(key: kOmemoDeviceId, defaultValue: 0)
|
|
static var omemoDeviceId: UInt32
|
|
|
|
@Storage(key: kSecureChatsByDefault, defaultValue: false)
|
|
static var secureChatsByDefault: Bool
|
|
}
|