- How do I clear all old save data and show only last data in core data xcode?
- 2012-07-22 18:40:51.787 TestSaveData[2329:fb03] Saved for number one
- 2012-07-22 18:40:55.159 TestSaveData[2329:fb03] Successfully load for test nombre one
- 2012-07-22 18:40:55.160 TestSaveData[2329:fb03] Successfully load for test number 2
- 2012-07-22 18:40:55.161 TestSaveData[2329:fb03] Successfully load for test number two
- 2012-07-22 18:40:55.161 TestSaveData[2329:fb03] Successfully load for test one
- 2012-07-22 18:40:55.162 TestSaveData[2329:fb03] Successfully load for test again
- 2012-07-22 18:40:55.163 TestSaveData[2329:fb03] Successfully load for
- 2012-07-22 18:40:55.164 TestSaveData[2329:fb03] Successfully load for test one
- 2012-07-22 18:40:55.165 TestSaveData[2329:fb03] Successfully load for test one again
- 2012-07-22 18:40:55.166 TestSaveData[2329:fb03] Successfully load for test one again
- 2012-07-22 18:40:55.166 TestSaveData[2329:fb03] Successfully load for 1
- 2012-07-22 18:40:55.167 TestSaveData[2329:fb03] Successfully load for (null)
- 2012-07-22 18:40:55.170 TestSaveData[2329:fb03] Successfully load for number one
- - (IBAction)button1:(id)sender
- {
- TestSaveDataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
- NSManagedObjectContext *context = [appDelegate managedObjectContext];
- Highscore *record = [NSEntityDescription insertNewObjectForEntityForName:@"Highscore" inManagedObjectContext:context];
- record.highscore1 = textField.text;
- NSLog(@"Saved for %@", textField.text);
- NSError *error;
- if (![context save:&error])
- {
- NSLog(@"Error");
- }
- }
- - (IBAction)button2:(id)sender
- {
- TestSaveDataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
- NSManagedObjectContext *context = [appDelegate managedObjectContext];
- NSFetchRequest *request = [[NSFetchRequest alloc] init];
- NSEntityDescription *entity = [NSEntityDescription entityForName:@"Highscore" inManagedObjectContext:context];
- [request setEntity:entity];
- NSError *error;
- if (![context save:&error])
- {
- NSLog(@"Error");
- }
- NSArray *array = [context executeFetchRequest:request error:&error];
- for (Highscore *record in array)
- {
- label.text = record.highscore1;
- NSLog(@"Successfully load for %@", record.highscore1);
- }
- }