Sono ancora nuovo in Core Data.Core Data sta salvando solo l'ultimo elemento
Sto provando ad eseguire il loop tre volte su un array e ad ogni ciclo, sto salvando il numero di indice.
Ma mostra solo l'ultimo numero di indice durante il recupero dei risultati. Sta scavalcando tutto ciò che è stato inserito prima.
Il mio codice è scritto in AppDelegate.
Ecco il mio codice:
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *tagsDB = [NSEntityDescription insertNewObjectForEntityForName:@"Tags" inManagedObjectContext:context];
for (int i = 0 ; i < 3 ; i++)
{
[tagsDB setValue:i forKey:@"ID"];
}
[self saveContext];
...
- (void)saveContext
{
NSError *error = nil;
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil) {
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
Quando ho ri-dichiarare la NSManagedObject ad ogni iterazione, tutti i dati vengono salvati ma ottengo sempre una riga supplementare di null valori – firewall