================
NSManagedObject category with Core Data helper methods for retrieving and saving data. Has method to save in separated thread
Firstly, check if this lines in category are correct for your Application Delegate.
#import "AppDelegate.h"
#define appDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
Also you need to init managedObjectContext with concurrency option
_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
All methods a duplicated for use with separate Core Data context or root context (appDelegate.managedObjectContext)
Then in code simply use:
NSPredicate *predicate;
predicate = [NSPredicate predicateWithFormat:@"userId = %@", appDelegate.manager.userId];
NSMutableArray *array = [NSManagedObject getFilteredRecordsWithPredicate:predicate localContext:localContext];
NSMutableArray *array = [NSManagedObject getAllRecords];
YourNiceObjectName *ts = [YourNiceObjectName createEntityInContext:localContext];
[NSManagedObject saveDefaultContext];
[NSManagedObject saveDataInBackgroundWithContext:^(NSManagedObjectContext *context) {
// your code for creating/updating data
//changes automatically merging in default context
} completion:^{
//your code
[Chainge saveDefaultContext]; //optional save default context
}];