IgorMuzyka / FileKit-RestorablePersistable

Missing extra conveniences of FileKit.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Restorable Persistable

Missing extra conveniences of FileKit.

Installation

Cocoapods

To install it, simply add the following line to your Podfile:

pod 'FileKit'
pod 'FileKit-RestorablePersistable', :git => 'https://github.com/IgorMuzyka/FileKit-RestorablePersistable.git'

Swift Package Manager

To install it add the following line to dependencies in your Package.swift file

.package(url: "https://github.com/IgorMuzyka/FileKit-RestorablePersistable", .branch("master"))

Usage

Conform to Codable

struct Object: Codable {
    
    let id: String
}

And then conform to RestorablePersistable

import FileKit_RestorablePersistable

extension Object: RestorablePersistable {
    
    static let fileExtension: String = ".object"
    var fileName: String { return id }
}

Now you able to save this type to disk or load from there at any time as follows

let object = Object(id: "0")
let file = try! object.persist(to: .userDocuments) // save object to user documents
let objectFromFile = try! file.restore() // load object from file
let objectFromPath = try! Object.restore(from: file.path) // load object from path

Author

Igor Muzyka, igormuzyka42@gmail.com

License

RestorablePersistable is available under the MIT license. See the LICENSE file for more info.

About

Missing extra conveniences of FileKit.

License:MIT License


Languages

Language:Swift 75.2%Language:Ruby 24.8%