I am a newbie and learning core data from scratch.
I’ve got the coredatamodel set up, then created NSManagedObject class. Then in the app delegate, I’ve tried to insert some test data. However, it did not work properly. Only the last data was inserted. Should I place
[self saveContext];
in between every object? In “applicationWillTerminate” method, saveContext method is called, hence the last item was saved. (is it correct?)
NSManagedObjectContext *context = [self managedObjectContext];
Vocabulary *vocabulary = [NSEntityDescription
insertNewObjectForEntityForName:@"Vocabulary"
inManagedObjectContext:context];
vocabulary.word = @"iPhone";
vocabulary.definition = @"better than Android";
vocabulary.level = @"beginner";
vocabulary.word = @"iPhone3gs";
vocabulary.definition = @"better than 3";
vocabulary.level = @"intermediate";
vocabulary.word = @"iPhone4";
vocabulary.definition = @"better than 3gs";
vocabulary.level = @"advanced";
vocabulary.word = @"iPhone4s";
vocabulary.definition = @"better than 4";
vocabulary.word = @"iPhone4s";
vocabulary.definition = @"64 is better than 32";
vocabulary.level = @"advanced";
You need to insert a new entity for each of the vocabulary objects you insert. So do this: