Swiftpack.co - num42/RxUserDefaults as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by num42.
num42/RxUserDefaults 6.2.2
Reactive UserDefaults
⭐️ 18
🕓 1 week ago
.package(url: "https://github.com/num42/RxUserDefaults.git", from: "6.2.2")




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:

  • Array (with types supported by UserDefaults)
  • Bool
  • Codable (using JSON Decoder)
  • Date (as ISO8601 String)
  • Double
  • Enum (enum must conform to the RxSettingEnum protocol)
  • Int
  • Set
  • String
  • UUID

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)

// Delete the value

// Provides a hot observable that triggers on every change and starts with the current value (or default value)

Storage Layer

If you prefer not to use UserDefaults as a storage layer, you can implement your own by confirming to the StorageLayer Protocol.

Warnings & TODOs

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.


Stars: 18
Last commit: 1 week ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1 week ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics