I am working with core data in my app. In that i am using below function to delete and insert data in core data database table. It works fine at first time. When i call 2nd time it throws EXC BAD ACCESS. Can anyone help to solve this.
@implementation abc
@synthesize delegate;
Dynamic *dbObjDynamic;
-(void) callingcoredata:(NSInteger) family type:(NSInteger) type List:(NSString *) list
{
if ([AppManager getAppMode] == Online)
{
statdyn = type;
arrDyanmic= [[NSMutableArray alloc]init];
dbObjDynamic = [[Dynamic alloc]init];
[dbObjDynamic DeleteRecordControlsFromTable:listtype];
}
}
In Dynamic.m
-(void)DeleteRecordControlsFromTable:(NSString *)listtype
{
NSManagedObjectContext *deleteContext = [self ManagedObjectContext];
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
[fetch setEntity:[NSEntityDescription entityForName:@"Dynamic" inManagedObjectContext:deleteContext]];
NSPredicate *predicate=[NSPredicate predicateWithFormat:@"listType == %@", listtype];
[fetch setPredicate:predicate];
NSError * error = nil;
NSArray * lookupdata = [deleteContext executeFetchRequest:fetch error:&error];
for(NSManagedObject *info in lookupdata)
{
[deleteContext deleteObject:info];
[deleteContext save:&error];
}
}
It throws error at dbObjDynamic = [[Dynamic alloc]init];
Thanks in advance.
You should alloc/init to the get instance of
Dynamic
managedObject class, Instead use this -and also call these method to get the fetchedResults of the
Dynamic
class managedObject from the managedObjectContext