Realm-powered Core Data persistent store
I like Realm. Realm's memory-mapped DB blows other databases out of the water. It's fast and memory efficient.
I also like Core Data. (disclaimer: I'm the author of CoreStore.) It's a very stable ORM framework and it works on top of any persistent store.
Here's the kicker: Core Data is stuck with SQLite until a better lightweight DB comes along, and Realm's database engine is phenomenal but its Cocoa framework is still lacking some features.
Fortunately, Core Data's NSIncrementalStore
interface lets us use the best of both worlds. RealmIncrementalStore
is an NSIncrementalStore
subclass that dynamically creates Realm schema using your Core Data models.
Here's an NSFetchedResultsController
running on Realm back-end (right: Realm Browser):
(Check the RealmIncrementalStoreDemo to see how it works)
That said, this project is still in its prototype stages and is more of a proof-of-concept than a working product. Use at your own risk!
Just include RealmIncrementalStore in your project and everything else is good old Core Data code. You just have to specify RealmIncrementalStore.storeType
when calling addPersistentStoreWithType()
on the NSPersistentStoreCoordinator
:
let coordinator = NSPersistentStoreCoordinator(...)
do {
try coordinator.addPersistentStoreWithType(
RealmIncrementalStore.storeType, // here
configuration: nil,
URL: url,
options: nil
)
}
catch {
// ...
}
Right now, most of Core Data's functionality works:
- Inserting / Updating / Deleting
- Fetching
NSFetchedResultsController
s- Relationships
- Basically most of what
NSIncrementalStore
s were designed to work in
(Pull Requests are welcome!)
Relationships (in progress, halfway there)Done- Migrations
- Fine-grained handling of
NSFetchRequest
s - Optimizations (still waiting for the Realm folks to open-source the realm-core)
- Try to implement
NSPredicates
that are not yet supported in Realm (?) - Benchmark!
https://github.com/JohnEstropia
RealmIncrementalStore is released under an MIT license. See the LICENSE file for more information