Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 2.28 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How do I clear all old save data and show only last data in core data xcode?
  2. 2012-07-22 18:40:51.787 TestSaveData[2329:fb03] Saved for number one
  3. 2012-07-22 18:40:55.159 TestSaveData[2329:fb03] Successfully load for test nombre one
  4. 2012-07-22 18:40:55.160 TestSaveData[2329:fb03] Successfully load for test number 2
  5. 2012-07-22 18:40:55.161 TestSaveData[2329:fb03] Successfully load for test number two
  6. 2012-07-22 18:40:55.161 TestSaveData[2329:fb03] Successfully load for test one
  7. 2012-07-22 18:40:55.162 TestSaveData[2329:fb03] Successfully load for test again
  8. 2012-07-22 18:40:55.163 TestSaveData[2329:fb03] Successfully load for
  9. 2012-07-22 18:40:55.164 TestSaveData[2329:fb03] Successfully load for test one
  10. 2012-07-22 18:40:55.165 TestSaveData[2329:fb03] Successfully load for test one again
  11. 2012-07-22 18:40:55.166 TestSaveData[2329:fb03] Successfully load for test one again
  12. 2012-07-22 18:40:55.166 TestSaveData[2329:fb03] Successfully load for 1
  13. 2012-07-22 18:40:55.167 TestSaveData[2329:fb03] Successfully load for (null)
  14. 2012-07-22 18:40:55.170 TestSaveData[2329:fb03] Successfully load for number one
  15.        
  16. - (IBAction)button1:(id)sender
  17. {
  18.     TestSaveDataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
  19.     NSManagedObjectContext *context = [appDelegate managedObjectContext];
  20.     Highscore *record = [NSEntityDescription insertNewObjectForEntityForName:@"Highscore" inManagedObjectContext:context];
  21.     record.highscore1 = textField.text;
  22.     NSLog(@"Saved for %@", textField.text);
  23.     NSError *error;
  24.     if (![context save:&error])
  25.     {
  26.         NSLog(@"Error");
  27.     }
  28. }
  29.        
  30. - (IBAction)button2:(id)sender
  31. {
  32.     TestSaveDataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
  33.     NSManagedObjectContext *context = [appDelegate managedObjectContext];
  34.     NSFetchRequest *request = [[NSFetchRequest alloc] init];
  35.     NSEntityDescription *entity = [NSEntityDescription entityForName:@"Highscore" inManagedObjectContext:context];
  36.     [request setEntity:entity];
  37.     NSError *error;
  38.     if (![context save:&error])
  39.     {
  40.         NSLog(@"Error");
  41.     }
  42.     NSArray *array = [context executeFetchRequest:request error:&error];
  43.     for (Highscore *record in array)
  44.     {
  45.         label.text = record.highscore1;
  46.         NSLog(@"Successfully load for %@", record.highscore1);
  47.     }
  48. }