another.im-ios/ConversationsClassic/Helpers/UserDefaultsWrapper.swift
2024-09-16 17:58:28 +02:00

33 lines
748 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"
enum UserSettings {
@Storage(key: kOmemoDeviceId, defaultValue: 0)
static var omemoDeviceId: UInt32
}