A simple, extensible CoreData stack that's simple to use and multithreaded
Objective-C
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
PCCoreDataStack
Samples
.gitignore
LICENSE
README.md

README.md

PCCoreDataStack

A simple, extensible CoreData stack that's simple to use and multithreaded

Purpose

Make concurrent CoreData operations easy. It achieves so by creating a default NSManagedObjectContext for the main thread, and creating multiple background NSManagedObjectContext for background operations. They all share the same NSPersistentStoreCoordinator which is where the contention for multithreaded operations is done (following the example of Marcus Zarra). This tool, paired with MOGenerator makes very clean and performant code.

Usage

Take a look into the sample application provided to check how to feed the information coming from a WebService into the CoreData stack concurrently. For example:

- (void) processBookResponse:(NSDictionary *)book
{
   [[PCCoreDataStack sharedInstance] performBackgroundCoreDataOperation:^(NSManagedObjectContext *backgroundMOC){
       
       //Create new book in background context!
       Book *newBook = [Book insertInManagedObjectContext:backgroundMOC];
       newBook.iID = book[@"id"];
       newBook.title = book[@"title"];
       newBook.detailsPath = book[@"link"];

   }];
}

Extension

The object PCCoreDataStack can be extended using categories for fetching information of a specific entity. Take a look how this is done in the sample application with the 'Books' entity

Supported iOS & SDK Versions

  • Supported build target - iOS 7.0 / Mac OS 10.9 (Xcode 5.0, Apple LLVM compiler 5.0)

NOTE: 'Supported' means that the library has been tested with this version.

ARC Compatibility

PCCoreDataStack requires ARC and uses weak references.