Am trying to delete row from core data base in ios application buts its not working,
if (editingStyle == UITableViewCellEditingStyleDelete) {
appDelegate = [[UIApplication sharedApplication] delegate];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"PRODUCTTABLE" inManagedObjectContext:appDelegate.managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
NSError *error;
NSManagedObject *matches = nil;
NSArray *objects = [appDelegate.managedObjectContext executeFetchRequest:request error:&error];
NSLog(@"Array Count....%d",[objects count]);
matches=[objects objectAtIndex:([indexPath row])];
NSLog(@"...%@",[matches valueForKey:@"productID"]);
NSLog(@"...%@",[matches valueForKey:@"pName"]);
NSLog(@"...%@",[matches valueForKey:@"pPrice"]);
NSLog(@"...%@",[matches valueForKey:@"pDate"]);
[appDelegate.managedObjectContext deleteObject:matches];
}
the o/p for following code:
Array Count....12
...ABC1226
...ABC-005
...599.39
...2012-08-09 05:07:50 +0000
am getting data from core data with same NSManagedObject. why delete not updating on Core data?
Save the context after changes.
NSError * error = nil;
[appDelegate.managedObjectContext deleteObject:matches];
[appDelegate.managedObjectContext save:&error];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With