https://github.com/hkellaway/purse
A fashionable accessory to persist data to disk :handbag:
https://github.com/hkellaway/purse
ios persistence swift
Last synced: 11 months ago
JSON representation
A fashionable accessory to persist data to disk :handbag:
- Host: GitHub
- URL: https://github.com/hkellaway/purse
- Owner: hkellaway
- License: mit
- Created: 2018-04-24T23:57:27.000Z (about 8 years ago)
- Default Branch: develop
- Last Pushed: 2018-10-10T23:24:35.000Z (almost 8 years ago)
- Last Synced: 2025-01-03T03:45:30.899Z (over 1 year ago)
- Topics: ios, persistence, swift
- Language: Swift
- Size: 66.4 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Purse :handbag:
A fashionable accessory to persist data to disk.
## Features
[](https://github.com/Carthage/Carthage)
[](https://travis-ci.org/hkellaway/Purse)
:lipstick: Persisting `Codable` objects to disk
:lipstick: Retrieving `Codable` objects from disk
## Getting Started
[Download Purse](https://github.com/hkellaway/Purse/archive/master.zip) 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
```ruby
pod 'Purse', '0.1.0'
```
### Installation with Carthage
```
github "hkellaway/Purse"
```
## Usage
### Codable
Let's say we have the following `Codable` model:
``` swift
struct Test: Codable {
let id: Int
let name: String
}
```
We can persist the model to the `/tmp` directory on disk by calling the following:
``` swift
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:
```swift
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:
```swift
Purse.shared.dataConverter = MyDataConverter()
```
## Credits
Purse was created by [Harlan Kellaway](http://harlankellaway.com).
## License
Purse is available under the MIT license. See the [LICENSE](https://raw.githubusercontent.com/hkellaway/Purse/master/LICENSE) file for more info.