https://github.com/r-dent/objectstore
A simple class that stores lists of `Codable` objects to JSON files.
https://github.com/r-dent/objectstore
ios json objectstore persistence swift
Last synced: about 2 months ago
JSON representation
A simple class that stores lists of `Codable` objects to JSON files.
- Host: GitHub
- URL: https://github.com/r-dent/objectstore
- Owner: r-dent
- Created: 2019-09-10T08:35:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-15T19:26:58.000Z (over 6 years ago)
- Last Synced: 2025-04-10T09:12:36.954Z (about 1 year ago)
- Topics: ios, json, objectstore, persistence, swift
- Language: Swift
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Poor Persons Object Store
A simple class that stores a list of `Codable` objects to a JSON file. Providing an easy to use persistence solution for small amounts of data.
The ObjectStore will save the data to JSON files in the ApplicationSupport directory.
## Installation
Just copy the contents of the [Sources](Sources) folder to your project.
## Usage
Make your datatypes conform to `Codable` and `ObjectStoreElement` by providing an `id` property.
```swift
struct TestData: Codable, ObjectStoreElement {
let id: Int // Required by ObjectStoreElement protocol.
let created: Date = Date()
let name: String
let uuid: String
let float: Float
}
```
Create an ObjectStore for your types.
```swift
db = JsonObjectStore(fileName: "testdata.json") { elements in
print("Found \(elements.count) objects.")
}
```
Add objects to the store.
```swift
db.add(TestData(
id: 3,
name: "A Name",
uuid: UUID().uuidString,
float: 2.345
))
```