Latest 0.1.1
Homepage https://github.com/num42/RxUserDefaults
License Apache 2.0
Platforms ios 8.0, tvos 9.0
Dependencies RxSwift, RxCocoa
Authors

CI Status
Version
License
Platform

Overview

Reactive UserDefaults, inspired by rx-preferences.

Typehandling was inspired by wrap and unbox

Usage

There is only one class called Setting.

To create a setting use the constructor of that class:

let setting = Setting<String>(userDefaults: userDefaults, key: "INSERT_KEY", defaultValue: "DEFAULT")

The arguments should be self explanatory.

Currently only following Types are supported:

  • String
  • Int
  • Bool
  • Array (only with the types supported by the UserDefaults)
  • Enum (but enum must conform to the RxSettingEnum protocol)

Functions you can use:

// gets the value
let val = setting.value 

// sets the value
setting.value = val 

// check if value is saved (note: the default value is not automatically saved)
setting.isSet

// deletes the value
setting.remove()

// provides a hot observable that triggers on every change
// and starts with the current value (or default value)
setting.asObservable()

Warnings & TODOs

I want to support everything that the UserDefaults support (e.g. Dictionary, URL …).
For now you can expand the library to more types by conforming to the RxSettingCompatible protocol.
But note that persisting types that are not supported by the UserDefaults will fail silently.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

RxUserDefaults is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "RxUserDefaults"
pod 'RxSwift', '3.0.0'

Requirements

Author

David Kraus, [email protected]

License

Copyright 2016 Number42

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Latest podspec

{
    "name": "RxUserDefaults",
    "version": "0.1.1",
    "summary": "Wrapper for userDefaults with RxSwift support.",
    "description": "<<-DESCn  Wrapper for userDefaults with RxSwift support.n                         DESC",
    "homepage": "https://github.com/num42/RxUserDefaults",
    "license": {
        "type": "Apache 2.0",
        "file": "LICENSE"
    },
    "authors": {
        "David Kraus": "[email protected]"
    },
    "source": {
        "git": "https://github.com/num42/RxUserDefaults.git",
        "tag": "0.1.1"
    },
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0"
    },
    "source_files": "RxUserDefaults/Classes/**/*",
    "dependencies": {
        "RxSwift": [
            "~> 3.0.0"
        ],
        "RxCocoa": [
            "~> 3.0.0"
        ]
    }
}

Pin It on Pinterest

Share This