A fashionable accessory to persist data to disk.
💄 Persisting Codable
objects to disk
💄 Retrieving Codable
objects from disk
Download Purse and perform a pod install
on the included Demo
app to see Purse in action
Purse is currently compatible with Swift 4.0.
pod 'Purse', '0.1.0'
github "hkellaway/Purse"
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)
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()
Purse was created by Harlan Kellaway.
Purse is available under the MIT license. See the LICENSE file for more info.