Skip to content

A fashionable accessory to persist data to disk 👜

License

Notifications You must be signed in to change notification settings

hkellaway/Purse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Purse 👜

A fashionable accessory to persist data to disk.

Features

Carthage compatible Build Status

💄 Persisting Codable objects to disk
💄 Retrieving Codable objects from disk

Getting Started

Download Purse and perform a pod install on the included Demo app to see Purse in action

Swift Version

Purse is currently compatible with Swift 4.0.

Installation with CocoaPods

pod 'Purse', '0.1.0'

Installation with Carthage

github "hkellaway/Purse"

Usage

Codable

Let's say we have the following Codable model:

struct Test: Codable {
    let id: Int
    let name: String
}

We can persist the model to the /tmp directory on disk by calling the following:

let test1 = Test(id: 1, name: "Test 1")
try Purse.shared.persist(test1, to: .temporary, fileName: "test1.json")

Similarly, we could retrieve the model from disk by calling:

let test1 = try Purse.shared.retrieve(from: .temporary, fileName: "test1.json", as: Test.self)

Advanced

Persisting in Other Formats But JSON

When persisting Codable objets to disk, Purse uses JSON as the format by default. If your data is in a different format that can be transformed to Data, you can create your own object that conforms to DataConverter then parameterize Purse with it:

Purse.shared.dataConverter = MyDataConverter()

Credits

Purse was created by Harlan Kellaway.

License

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

About

A fashionable accessory to persist data to disk 👜

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published