0

Im developing a iphone app and for DB im using core data. While saving the core data works properly.

But once in a while, the saving fails. This cause duplicate records in my app. I have 2 tables

  1. Parent table

  2. Child table

When child table fails and user tries to save again, multiple parents records are created. My questions are:

  1. Why core data fails. Since its rare im not able to find why it fails. What could be the reason?
  2. Is there any way to roll back the data of parent table also if child table fails to save.

Thanks in advance :)

cancerian
  • 942
  • 1
  • 10
  • 18

1 Answers1

0

1. Why core data fails. Since its rare i'm not able to find why it fails. What could be the reason? Since you haven't write any code so its very tough to detect, when you are saving data to core data , you can log the error if it not successfully save then you will be able to know the exact cause of problem.

NSError *error;
if (![managedObjectContext save:&error]) {
    NSLog(@"Failed to save - error: %@", [error localizedDescription]);
}

2. Is there any way to roll back the data of parent table also if child table fails to save. No, I don't think it is possible to rollback. in such case what i do I always check if the data is already inserted or not for following id, if not then i will enter that data and vice-versa.

Manish Agrawal
  • 10,958
  • 6
  • 44
  • 76