Skip to content

BottleRocketStudios/iOS-Holocron

Repository files navigation

Holocron

codecov codebeat badge

Purpose

This library provides a simple abstraction around the common methods of persisting data, such as UserDefaults, the Keychain and the file system.

Usage

An instance of UserDefaultsPersistence, KeychainPersistence or FilePersistence needs to be created so that you can perform common operations like write, read and delete. While UserDefaultsPersistence and FilePersistence have no outside dependencies, KeychainPersistence uses the KeychainAccess Cocoapod when interacting with the Keychain.

Below are examples of how to set up each individual persistence type and store some object using it:

// UserDefaults
let userDefaultsPersistence = UserDefaultsPersistence()
try? userDefaultsPersistence.write(object: myObject, for: "someKey")
// Keychain
let keychainPersistence = KeychainPersistence(keychainServiceName: "com.holocron.test")
try? keychainPersistence.write(object: myObject, for: "someKeychainKey")
// File Management
let filePersistence = FilePersistence(directory: cacheDirectory)
let fileStore = FileStore(fileName: "testFilePersistance")
filePersistence.write(object: myObject, for: fileStore) { result in
    switch result {
    case .success(let object): print("\(object) was written to disk!")
    case .failure(let error): print("Error: \(error)")
    }
}

Version License Platform

Example

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

Requirements

Requires iOS 8.0+, Swift 4.0

Installation

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

pod 'Holocron'

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published