Skip to content

Latest commit

 

History

History
76 lines (50 loc) · 2.29 KB

README.md

File metadata and controls

76 lines (50 loc) · 2.29 KB

TLDataManager

Version Platform

Usage

To run the example project; clone the repo, and run pod install from the Example directory first.

Static Singleton

The singleton is useful for managing a single CoreData stack for your application. For most applications, one CoreData stack is sufficient.

[TLDataManager setDatabaseName:@"MY_DB_NAME" linkedToModel:@"MY_MODEL_NAME"];
[TLDataManager sharedManager];

Initialization

For applications that require multiple CoreData stacks, you can initalize your own TLDataManager instance.

// create the manager
TLDataManager *manager = [[TLDataManager alloc] initWithDatabaseName:@"MY_DB_NAME" 
                                                       linkedToModel:@"MY_MODEL_NAME"];

// do something with the main context
[manager.mainContext ...]

Import Data

Importing data on a background thread is easy if you follow a few simple rules.

// reference the manager
TLDataManager *manager = [TLDataManager sharedManager];

// import data and pass in block to be executed on a background thread
// there is a reference to a background context that should be used for importing data
[manager importData:^(NSManagedObjectContext *context){
    
    // perform long import
    NSCustomManagedObject *object = [NSCustomManagedObject longImportInContext:context];

    // return block to be called on main thread
    return ^{
        // reference main context
        NSManagedObjectContext *mainContext = manager.mainContext;
        // reference imported object(s) on main thread
        NSCustomManagedObject *newObject = [context objectWithID:object.objectID];
        // ... callback with newObject on main thread ...
    }
}];

Requirements

iOS 6.1 or later

Installation

TLDataManager is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "TLDataManager"

Author

Andrew Barba, [email protected]

License

TLDataManager is available under the MIT license. See the LICENSE file for more info.