Giter Site home page Giter Site logo

coredatafullstack-ios's Introduction

CoreDataFullStack-iOS

Version License Platform CocoaPods Build Status

What is it?

Easiest way to build a Core Data full stack.

Stack

This project stack consists of two independent managed object contexts which are both connected to the same persistent store coordinator.

alt tag

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.

FetchedResultsController

Core data make sense to use with an FRC. The project comes with the basic FRC implementation for a table and collection view.

Accessing Core Data

TODO: The project will have a full suite to access the objects.

Installation

Podfile

platform :ios, '8.0'
pod 'CoreDataFullStack', '~> 0.4'

Then, run the following command:

$ pod install

Old school

Drag into your project the folder /CoreDataFullStack-iOS. That's all.

How to

General rule

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

IMPORTANT

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.

Stack Set up

//  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";
}

Insert

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];
    }];

Retrieve

    NSArray *entries = [CDFRetrievalService retrieveEntriesForEntityClass:[CDFHouse class] managedObjectContext:[CDFCoreDataManager sharedInstance].managedObjectContext];

Delete

    [[CDFCoreDataManager sharedInstance].backgroundManagedObjectContext performBlockAndWait:^
     {
         [CDFDeletionService deleteEntriesForEntityClass:[CDFHouse class]
                                       saveAfterDeletion:YES
                                    managedObjectContext:[CDFCoreDataManager sharedInstance].backgroundManagedObjectContext];
     }];

Count

	NSArray *entries = [CDFRetrievalService retrieveEntriesForEntityClass:[CDFHouse class]
                                                     managedObjectContext:[CDFCoreDataManager sharedInstance].managedObjectContext];

License

CoreDataFullStack-iOS is released under the MIT license. Please see the file called LICENSE.

Versions

$ git tag -a 0.4.0 -m 'Version 0.4.0'

$ git push --tags

Author

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.

coredatafullstack-ios's People

Contributors

gabrielmassana avatar

Watchers

Fayyazuddin Syed avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.