SkillAgentSearch skills...

NWCoreDataHelper

NSManagedObject category with Core Data helper methods for retrieving and saving data

Install / Use

/learn @ArchieGoodwin/NWCoreDataHelper
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

NWCoreDataHelper

================

NSManagedObject category with Core Data helper methods for retrieving and saving data. Has method to save in separated thread

Usage

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:

Get records with NSPredicate in context

        NSPredicate *predicate;
        predicate = [NSPredicate predicateWithFormat:@"userId = %@", appDelegate.manager.userId];
        NSMutableArray *array =  [NSManagedObject getFilteredRecordsWithPredicate:predicate localContext:localContext];

Get all recrods

        NSMutableArray *array = [NSManagedObject getAllRecords];

Create entity

        YourNiceObjectName *ts = [YourNiceObjectName createEntityInContext:localContext];

Save default context

        [NSManagedObject saveDefaultContext];

Save in separate context:

        [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
                       
                    }];
View on GitHub
GitHub Stars5
CategoryDevelopment
Updated2y ago
Forks2

Languages

Objective-C

Security Score

55/100

Audited on Oct 3, 2023

No findings