I noticed a problem with the code, when I try to insert a new record into an entity, I lose all the old records and only the new one gets saved.
Code used:
NSManagedObjectContext * context = [self managedObjectContext];
NSManagedObjectContext * novoObjeto = [NSEntityDescription insertNewObjectForEntityForName: entidadeBebidas inManagedObjectContext: context];
[novoObjeto setValue: novoValor forKey: @ "id"];
NSError * error = nil;
if (![context save: & error]) {
//[self alertaErroCadastro];
//NSLog(@"Erro ao salvar no banco local");
}
Before insertion:
| id |
12542
12542
25412
21452
After inserting the new record:
| id |
998698
Previous records are lost.