Latest 1.1.0
Homepage https://github.com/maxsokolov/Kee
License MIT
Platforms ios 8.0
Dependencies KeychainAccess
Authors

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

CocoaPods

To integrate Kee into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'Kee'

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.

Latest podspec

{
    "name": "Kee",
    "module_name": "Kee",
    "version": "1.1.0",
    "homepage": "https://github.com/maxsokolov/Kee",
    "summary": "Generic key value storage.",
    "authors": {
        "Max Sokolov": "https://twitter.com/max_sokolov"
    },
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Sources/*.swift",
    "source": {
        "git": "https://github.com/maxsokolov/Kee.git",
        "tag": "1.1.0"
    },
    "dependencies": {
        "KeychainAccess": [
            "~> 3.0"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This