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

License

Overview

RxUserDefaults is a reactive solution for managing user defaults, inspired by rx-preferences with type handling influenced by wrap and unbox.

Usage

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)
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()

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.

Installation

RxUserDefaults is available through SPM.

Requirements

Authors

License

Licensed under the Apache License, Version 2.0. See the License for details.

GitHub

link
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