Easiest way to build a Core Data full stack.
This project stack consists of two independent managed object contexts which are both connected to the same persistent store coordinator.
The Core Data stack used follows the Florian Kugler's third example from this article.
Florian Kugler's investigation shows how this Core Data Stack is the faster one.
Core data make sense to use with an FRC. The project comes with the basic FRC implementation for a table and collection view.
TODO: The project will have a full suite to access the objects.
platform :ios, '8.0'
pod 'CoreDataFullStack', '~> 0.4'
Then, run the following command:
$ pod install
Drag into your project the folder /CoreDataFullStack-iOS
. That's all.
To modify the database (insert new object, delete, update) access via the background backgroundManagedObjectContext
.
To retrieve data to be shown in the UI access via the MainThread managedObjectContext
To avoid crossing threads use performBlockAndWait:^
with the backgroundManagedObjectContext
[[CDFCoreDataManager sharedInstance].backgroundManagedObjectContext performBlockAndWait:^
{
// Insert
// Delete
// Update
}
Go to Edit Scheme.../ Arguments / Arguments Passed On Launch and add: -com.apple.CoreData.ConcurrencyDebug 1
This line will tell you if you are crossing threads in your app.
To avoid problems be totally sure that your app is not crossing threads.
// AppDelegate.m
#import "CoreDataFullStack.h"
@interface AppDelegate () <CDFCoreDataManagerDelegate>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[CDFCoreDataManager sharedInstance].delegate = self;
return YES;
}
#pragma mark - CDFCoreDataManagerDelegate
- (NSString *)coreDataModelName
{
return @"ModelName";
}
Use CoreData system. It is really easy.
[[CDFCoreDataManager sharedInstance].backgroundManagedObjectContext performBlockAndWait:^
{
CDFHouse *firstHouse = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([CDFHouse class])
inManagedObjectContext:[CDFCoreDataManager sharedInstance].backgroundManagedObjectContext];
firstHouse.houseID = @"0";
firstHouse.town = @"London";
CDFPerson *firstPerson = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([CDFPerson class])
inManagedObjectContext:[CDFCoreDataManager sharedInstance].backgroundManagedObjectContext];
firstPerson.personID = @"0";
firstPerson.name = @"John";
firstPerson.house = firstHouse;
[[CDFCoreDataManager sharedInstance].backgroundManagedObjectContext save:nil];
}];
NSArray *entries = [CDFRetrievalService retrieveEntriesForEntityClass:[CDFHouse class] managedObjectContext:[CDFCoreDataManager sharedInstance].managedObjectContext];
[[CDFCoreDataManager sharedInstance].backgroundManagedObjectContext performBlockAndWait:^
{
[CDFDeletionService deleteEntriesForEntityClass:[CDFHouse class]
saveAfterDeletion:YES
managedObjectContext:[CDFCoreDataManager sharedInstance].backgroundManagedObjectContext];
}];
NSArray *entries = [CDFRetrievalService retrieveEntriesForEntityClass:[CDFHouse class]
managedObjectContext:[CDFCoreDataManager sharedInstance].managedObjectContext];
CoreDataFullStack-iOS is released under the MIT license. Please see the file called LICENSE.
$ git tag -a 0.4.0 -m 'Version 0.4.0'
$ git push --tags
Gabriel Massana
##Found an issue?
Please open a new Issue here if you run into a problem specific to CoreDataFullStack-iOS, have a feature request, or want to share a comment.