Hi I am fairly new to core data and have recently started doing some tutorials. I have successfully added new data via core data but am struggling to overwrite the data. I have a textfield where I want to be able to save the text written in that textfield to core data. This is how I have added new data. Can anyone lead me in the right direction?
Thank you
P.S. I believe it has to do with the way I do “insertNewObjectForEntityForName”
-(IBAction)saveData
{
AppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context =
[appDelegate managedObjectContext];
NSManagedObject *newContact;
newContact = [NSEntityDescription
insertNewObjectForEntityForName:@"Gameinfo"
inManagedObjectContext:context];
[newContact setValue:[self valuefromtextfield] forKey:@"score"];
//[newContact setValue:@"mark" forKey:@"currentLevel"];
NSError *error;
[context save:&error];
}
When you use
insertNewObjectForEntityForNameyou are creating a NEW entity. If you want to edit an existing entity you need toThen
someArrayhas all of the entities namedGameinfoin it. Find the one you want and edit whatever properties you want. Then callsaveon the managed object context.