TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2015 |
SPMSupports SPM | ✗ |
Maintained by Daniel Tomlinson.
Persist is a simple, reusable Core Data stack written in Swift. It also provides some lightweight helpers for common actions such as creating entities and querying.
It supports iOS 8+, watchOS 2.0, and Mac OS 10.9+.
Persist uses a simple parent/child Core Data stack, with a private writer context attached directly to the NSPersistentStoreCoordinator, with a main queue context that is exposed to the user as its child.
┌─────────────────────────────────────────────────────────────────────────┐
│ ┌─────────────────────────────────┐ │
│ │ Persistent Store Coordinator │ │
│ └────────────────┬────────────────┘ │
│ │ │
│ │ │
│ ┌────────────────▼────────────────┐ │
│ │ Private Queue Context │ │
│ └────────────────┬────────────────┘ │
│ │ │
│ │ │
│ ┌────────────────▼────────────────┐ ┌─────────────────┐ │
│ │ Main Queue Context ├─────────▶ User Interface │ │
│ └────────────────┬────────────────┘ └─────────────────┘ │
│ │ │
│ │ │
│ │ │
│ │ │
│ │ │
│ ┌────────────────▼────────────────┐ ┌────────────────────────┐ │
│ │ Temporary Private Queue Context ◀─────────┤ Writes/Updates │ │
│ └─────────────────────────────────┘ └────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘
Persist gives you full access to the configuration of its underlying stores
via the StoreType
enum, providing safe construction of InMemory, SQLite, and
Binary store types, and allows you to also provide a custom store type.
Creating an in-memory store would look like this:
import Persist
let bundle = NSBundle.mainBundle()
let modelPath = bundle.pathForResource("MyModel", ofType: "momd")!
let modelURL = NSURL(fileURLWithPath: modelPath)
let persist = try! Persist(storeType: .InMemory, modelURL: modelURL)
You can see more examples in PersistTests/PersistStoreBasedTests.swift
To opt your NSManagedObject subclasses into the helpers, annotate them with the ManagedObjectType protocol like so:
@objc(Person)
class Person: ManagedObjectType {
}
If you don't provide an objective-c name for your class, or update your model
configuration to support module namespaces, you will need to provide your own
implementation of static func entityName() -> String
.
Issues and feature requests are welcome, although the intention is to keep Persist lightweight.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)