DATAStack alternatives and similar libraries
Based on the "Core Data" category.
Alternatively, view DATAStack alternatives based on common mentions on social networks and blogs.
-
CoreStore
Unleashing the real power of Core Data with the elegance and safety of Swift -
QueryKit
A simple CoreData query language for Swift and Objective-C. -
encrypted-core-data
v2.0 - iOS Core Data encrypted SQLite store using SQLCipher -
AlecrimCoreData
A powerful and simple Core Data wrapper framework written in Swift. -
Graph
Graph is a semantic database that is used to create data-driven applications. -
PrediKit
An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift. -
AERecord
Super awesome Swift minion for Core Data (iOS, macOS, tvOS) -
ios-queryable
ios-queryable is an implementation of IQueryable/IEnumerable for Core Data -
Skopelos
A minimalistic, thread safe, non-boilerplate and super easy to use version of Active Record on Core Data. Simply all you need for doing Core Data. Swift flavour. -
HardCoreData
CoreData stack and controller that will never block UI thread -
JustPersist
JustPersist is the easiest and safest way to do persistence on iOS with Core Data support out of the box. It also allows you to migrate to any other persistence framework with minimal effort. -
SLRESTfulCoreData
Objc naming conventions, autogenerated accessors at runtime, URL substitutions and intelligent attribute mapping -
CloudCore
Robust CoreData-CloudKit synchronization, including offline queuing, relationships, private, shared and public databases, field-level deltas, encrypted values, maskable attributes, cacheable assets, and more. -
Cadmium
A Swift framework that wraps CoreData, hides context complexity, and helps facilitate best practices. -
CWCoreData
Additions and utilities to make it concurrency easier with the Core Data framework. -
PredicateFlow
Write amazing, strong-typed and easy-to-read NSPredicate. -
CoreDataDandy
A feature-light wrapper around Core Data that simplifies common database operations. -
Core Data Query Interface
A type-safe, fluent Swift library for working with Core Data
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of DATAStack or a related project?
README
DATAStack helps you to alleviate the Core Data boilerplate. Now you can go to your AppDelegate remove all the Core Data related code and replace it with an instance of DATAStack ([ObjC](DemoObjectiveC/AppDelegate.m), [Swift](DemoSwift/AppDelegate.swift)).
- Easier thread safety
- Runs synchronously when using unit tests
- No singletons
- SQLite and InMemory support out of the box
- Easy database drop method
- Shines with Swift
- Compatible with Objective-C
- Free
Table of Contents
- Running the demos
- Initialization
- Main Thread NSManagedObjectContext
- Background Thread NSManagedObjectContext
- Clean up
- Testing
- Migrations
- Installation
- Be Awesome
- Author
- License
Running the demos
- Clone the repository
- Open the
Demo.xcodeproj
- Enjoy!
Initialization
You can easily initialize a new instance of DATAStack with just your Core Data Model name (xcdatamodel).
Swift
let dataStack = DATAStack(modelName:"MyAppModel")
Objective-C
DATAStack *dataStack = [[DATAStack alloc] initWithModelName:@"MyAppModel"];
There are plenty of other ways to intialize a DATAStack:
- Using a custom store type.
let dataStack = DATAStack(modelName:"MyAppModel", storeType: .InMemory)
- Using another bundle and a store type, let's say your test bundle and .InMemory store type, perfect for running unit tests.
let dataStack = DATAStack(modelName: "Model", bundle: NSBundle(forClass: Tests.self), storeType: .InMemory)
- Using a different name for your .sqlite file than your model name, like
CustomStoreName.sqlite
.
let dataStack = DATAStack(modelName: "Model", bundle: NSBundle.mainBundle(), storeType: .SQLite, storeName: "CustomStoreName")
- Providing a diferent container url, by default we'll use the documents folder, most apps do this, but if you want to share your sqlite file between your main app and your app extension you'll want this.
let dataStack = DATAStack(modelName: "Model", bundle: NSBundle.mainBundle(), storeType: .SQLite, storeName: "CustomStoreName", containerURL: sharedURL)
Main Thread NSManagedObjectContext
Getting access to the NSManagedObjectContext attached to the main thread is as simple as using the mainContext
property.
self.dataStack.mainContext
or
self.dataStack.viewContext
Background Thread NSManagedObjectContext
You can easily create a new background NSManagedObjectContext for data processing. This block is completely asynchronous and will be run on a background thread.
To be compatible with NSPersistentContainer you can also use performBackgroundTask
instead of performInNewBackgroundContext
.
Swift
func createUser() {
self.dataStack.performInNewBackgroundContext { backgroundContext in
let entity = NSEntityDescription.entityForName("User", inManagedObjectContext: backgroundContext)!
let object = NSManagedObject(entity: entity, insertIntoManagedObjectContext: backgroundContext)
object.setValue("Background", forKey: "name")
object.setValue(NSDate(), forKey: "createdDate")
try! backgroundContext.save()
}
}
Objective-C
- (void)createUser {
[self.dataStack performInNewBackgroundContext:^(NSManagedObjectContext * _Nonnull backgroundContext) {
NSEntityDescription *entity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:backgroundContext];
NSManagedObject *object = [[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:backgroundContext];
[object setValue:@"Background" forKey:@"name"];
[object setValue:[NSDate date] forKey:@"createdDate"];
[backgroundContext save:nil];
}];
}
When using Xcode's Objective-C autocompletion the backgroundContext
parameter name doesn't get included. Make sure to add it.
Clean up
Deleting the .sqlite
file and resetting the state of your DATAStack is as simple as just calling drop
.
Swift
self.dataStack.drop()
Objective-C
[self.dataStack forceDrop];
Testing
DATAStack is optimized for unit testing and it runs synchronously in testing enviroments. Hopefully you'll have to use less XCTestExpectations now.
You can create a stack that uses in memory store like this if your Core Data model is located in your app bundle:
Swift
let dataStack = DATAStack(modelName: "MyAppModel", bundle: NSBundle.mainBundle(), storeType: .InMemory)
Objective-C
DATAStack *dataStack = [[DATAStack alloc] initWithModelName:@"MyAppModel"
bundle:[NSBundle mainBundle]
storeType:DATAStackStoreTypeInMemory];
If your Core Data model is located in your test bundle:
Swift
let dataStack = DATAStack(modelName: "MyAppModel", bundle: NSBundle(forClass: Tests.self), storeType: .InMemory)
Objective-C
DATAStack *dataStack = [[DATAStack alloc] initWithModelName:@"MyAppModel"
bundle:[NSBundle bundleForClass:[self class]]
storeType:DATAStackStoreTypeInMemory];
(Hint: Maybe you haven't found the best way to use NSFetchedResultsController, well here it is.)
Migrations
If DATAStack
has troubles creating your persistent coordinator because a migration wasn't properly handled it will destroy your data and create a new sqlite file. The normal Core Data behaviour for this is making your app crash on start. This is not fun.
Installation
DATAStack is available through CocoaPods. To install it, simply add the following line to your Podfile:
use_frameworks!
pod 'DATAStack', '~> 6'
DATAStack is also available through Carthage. To install it, simply add the following line to your Cartfile:
github "SyncDB/DATAStack" ~> 6.0
Be Awesome
If something looks stupid, please create a friendly and constructive issue, getting your feedback would be awesome.
Have a great day.
Author
Elvis Nuñez, @3lvis
License
DATAStack is available under the MIT license. See the LICENSE file for more info.
*Note that all licence references and agreements mentioned in the DATAStack README section above
are relevant to that project's source code only.