RxUserDefaults is a reactive solution for managing user defaults, inspired by rx-preferences with type handling influenced by wrap and unbox.
To create a setting, initialize the class using its constructor:
let settings = RxSettings(userDefaults: userDefaults)
let setting = settings.setting(key: "INSERT_KEY", defaultValue: "DEFAULT")
The arguments are self-explanatory.
Supported Types:
Functions available:
// Retrieve the value
let val = setting.value
// Set the value
setting.value = val
// Check if the value is saved (note: the default value is not automatically saved)
setting.isSet
// Delete the value
setting.remove()
// Provides a hot observable that triggers on every change and starts with the current value (or default value)
setting.asObservable()
If you prefer not to use UserDefaults as a storage layer, you can implement your own by confirming to the StorageLayer Protocol.
The goal is to support all types that UserDefaults supports (e.g., Dictionary, URL). For now, you can expand the library to more types by conforming to the RxSettingCompatible protocol. However, note that persisting types not supported by UserDefaults will fail silently.
RxUserDefaults is available through SPM.
Licensed under the Apache License, Version 2.0. See the License for details.
link |
Stars: 18 |
Last commit: 2 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics