Kee 1.1.0

Kee 1.1.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Feb 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Max Sokolov.



Kee 1.1.0

  • By
  • Max Sokolov

Kee

Kee is a simple key-value persistance library written in Swift with type-safety in mind. It allows you to store primitives like Int or String and any complex objects which can be represented as a key-value Dictionary.

Features

  • [x] Support primitives (Int, String, etc.), Arrays and Dictionaries
  • [x] Support Keychain
  • [x] Support UserDefaults
  • [x] Support File storage - you could persist your values on disk
  • [x] Extensible - you could easily add your own storage
  • [x] Tests

Requirements

  • Swift 3.0
  • iOS 8.0 or greater
  • Xcode 8.0 or newer

Getting Started

Load and save primitives

Save to storage

let storage = KeyValueStorageFactory().defaultsStorage()

let myValue: Float = 42.0

try? storage.setValue(myValue, forKey: "myKey")

Load from storage

let storage = KeyValueStorageFactory().defaultsStorage()

let myValue: Float? = storage.getValue(forKey: "myKey")

Or using try/catch

let storage = KeyValueStorageFactory().defaultsStorage()

do {
    let myValue: Float = try storage.getValue(forKey: "myKey")
} catch let error {
    // handle error if needed
}

Load and save custom objects

Let’s say you have a custom User object that you want to persist

struct User {

    let username: String
}

You have to conform to the KeyValueRepresentable to allow object to be archived

extension User: KeyValueRepresentable {

    var keyValueRepresentation: KeyValueRepresentation {
        return [
            "username": username
        ]
    }

    init(keyValueRepresentation rep: KeyValueRepresentation) throws {

        username = rep["username"] as? String ?? ""
    }
}

Save to storage

let storage = KeyValueStorageFactory().defaultsStorage()

let user = User(username: "John Doe")

try? storage.setObject(user, forKey: "user")

Load from storage

let storage = KeyValueStorageFactory().defaultsStorage()

let user: User? = storage.getObject(forKey: "user")

Installation

Manual

Clone the repo and drag files from Sources folder into your Xcode project.

License

Kee is available under the MIT license. See LICENSE for details.