generate sub class in Editor > Create NSManagedContext SubClass
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[mmDAO instance] setupEnvModel:@"asyncCoreDataWrapper" DbFile:@"asyncCoreDataWrapper.sqlite"];
return YES;
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Saves changes in the application's managed object context before the application terminates.
[self saveContext];
}
- (void)saveContext
{
NSError *error = nil;
if ([[mmDAO instance].bgObjectContext hasChanges]) {
[[mmDAO instance].bgObjectContext save:&error];
}
}
#import <Availability.h>
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "NSManagedObject+helper.h"
#endif
Entity *task = [Entity createNew];
task.task_id = @([self genId]);
task.title = _txInputBox.text;
task.detail = @"[not sure]";
task.done = NO;
Entity *task = _dataArray[indexPath.row];
[Entity delobject:task];
[Entity save:^(NSError *error) {
_txInputBox.text = @"";
[self fetchEntitys];
}];
NSArray *results = [Entity filter:@"task_id>10" orderby:@[@"task_id"] offset:0 limit:0];
[Entity filter:nil orderby:@[@"task_id"] offset:0 limit:0 on:^(NSArray *result, NSError *error) {
_dataArray = result;
[_mainTable reloadData]; //reload table view
}];
[Entity async:^id(NSManagedObjectContext *ctx, NSString *className) {
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:className];
[request setSortDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"task_id" ascending:YES]]];
NSError *error;
NSArray *dataArray = [ctx executeFetchRequest:request error:&error];
if (error) {
return error;
}else{
return dataArray;
}
} result:^(NSArray *result, NSError *error) {
_dataArray = result;
[_mainTable reloadData];
}];