Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A static library project that simplifies Core Data.

License

NotificationsYou must be signed in to change notification settings

GabrielMassana/CoreDataFullStack-iOS

Repository files navigation

VersionLicensePlatformCocoaPodsBuild 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 fromthis 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 backgroundbackgroundManagedObjectContext.

To retrieve data to be shown in the UI access via the MainThreadmanagedObjectContext

IMPORTANT

To avoid crossing threads useperformBlockAndWait:^ with thebackgroundManagedObjectContext

[[CDFCoreDataManagersharedInstance].backgroundManagedObjectContextperformBlockAndWait:^    {// 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"@interfaceAppDelegate () <CDFCoreDataManagerDelegate>- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    [CDFCoreDataManagersharedInstance].delegate = self;returnYES;}#pragma mark - CDFCoreDataManagerDelegate- (NSString *)coreDataModelName{return@"ModelName";}

Insert

Use CoreData system. It is really easy.

[[CDFCoreDataManagersharedInstance].backgroundManagedObjectContextperformBlockAndWait:^    {        CDFHouse *firstHouse = [NSEntityDescriptioninsertNewObjectForEntityForName:NSStringFromClass([CDFHouseclass])inManagedObjectContext:[CDFCoreDataManagersharedInstance].backgroundManagedObjectContext];                firstHouse.houseID =@"0";        firstHouse.town =@"London";                CDFPerson *firstPerson = [NSEntityDescriptioninsertNewObjectForEntityForName:NSStringFromClass([CDFPersonclass])inManagedObjectContext:[CDFCoreDataManagersharedInstance].backgroundManagedObjectContext];                firstPerson.personID =@"0";        firstPerson.name =@"John";        firstPerson.house = firstHouse;        [[CDFCoreDataManagersharedInstance].backgroundManagedObjectContextsave:nil];    }];

Retrieve

NSArray *entries = [CDFRetrievalServiceretrieveEntriesForEntityClass:[CDFHouseclass]managedObjectContext:[CDFCoreDataManagersharedInstance].managedObjectContext];

Delete

    [[CDFCoreDataManagersharedInstance].backgroundManagedObjectContextperformBlockAndWait:^     {         [CDFDeletionServicedeleteEntriesForEntityClass:[CDFHouseclass]saveAfterDeletion:YESmanagedObjectContext:[CDFCoreDataManagersharedInstance].backgroundManagedObjectContext];     }];

Count

NSArray *entries = [CDFRetrievalServiceretrieveEntriesForEntityClass:[CDFHouseclass]managedObjectContext:[CDFCoreDataManagersharedInstance].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 anew Issue here if you run into a problem specific to CoreDataFullStack-iOS, have a feature request, or want to share a comment.

About

A static library project that simplifies Core Data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp