Guest User

Untitled

a guest
Jan 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. NSFetchRequest *oldFetchRequest = [[NSFetchRequest alloc] init];
  2. NSEntityDescription *oldEntryEntity = [NSEntityDescription entityForName:@"Entry"
  3. inManagedObjectContext:oldContext];
  4. [oldFetchRequest setEntity:oldEntryEntity];
  5. [oldFetchRequest setFetchBatchSize:10];
  6. [oldFetchRequest setIncludesPropertyValues:NO];
  7. NSArray *entrys = [oldContext executeFetchRequest:oldFetchRequest error:&error];
  8.  
  9. int totalEntries = [oldContext countForFetchRequest:oldFetchRequest error:nil];
  10.  
  11. int i = 0;
  12.  
  13. while (i < totalEntries) {
  14. @autoreleasepool {
  15.  
  16. Entry *entry = [entrys objectAtIndex:i];
  17.  
  18. NSLog(@"message 1: %@", [entry valueForKey:@"message"]);
  19.  
  20.  
  21. [oldContext reset];
  22.  
  23.  
  24. i++;
  25. }
  26. }
  27.  
  28. NSFetchRequest *oldFetchRequest = [[NSFetchRequest alloc] init];
  29. NSEntityDescription *oldEntryEntity =
  30. [NSEntityDescription entityForName:@"Entry"
  31. inManagedObjectContext:oldContext];
  32. [oldFetchRequest setEntity:oldEntryEntity];
  33. [oldFetchRequest setFetchBatchSize:10];
  34. [oldFetchRequest setIncludesPropertyValues:NO];
  35. NSArray *entrys = [oldContext executeFetchRequest:oldFetchRequest error:&error];
  36. int totalEntries = [oldContext countForFetchRequest:oldFetchRequest error:nil];
  37.  
  38. NSLog(@"entrys count = %u", entrys.count);
  39. for (NSManagedObject *entry in entrys) {
  40. NSLog(@"entry: %@", entry);
  41. }
  42.  
  43. int i = 0;
  44. while (i < totalEntries) {
  45. @autoreleasepool {
  46. // You get the i-th entry. It will be a managed object. It could be a fault
  47. // or it could be a fully hydrated object. Based on your batch size, the
  48. // first ten (0 <= i < 10) will be complete objects.
  49. Entry *entry = [entrys objectAtIndex:i];
  50.  
  51. // Log the "message" attribute. By calling valueForKey, the object will be
  52. // faulted into memory if it is a fault. Since your batch size is 10,
  53. // this will make sure 10 objects are faulted if one is needed.
  54. NSLog(@"message 1: %@", [entry valueForKey:@"message"]);
  55.  
  56. // Resetting the entire context blows away everything in the context.
  57. // Calling reset is a hard call, and should not be done if you have
  58. // references to the objects in the context.
  59. [oldContext reset];
  60.  
  61. i++;
  62. }
  63. }
  64.  
  65. - (void)refreshObject:(NSManagedObject *)object mergeChanges:(BOOL)flag
  66.  
  67. while (i < totalEntries) {
  68. @autoreleasepool {
  69.  
  70. Entry *entry = [entrys objectAtIndex:i];
  71.  
  72. NSLog(@"message 1: %@", [entry valueForKey:@"message"]);
  73.  
  74.  
  75. [oldContext refreshObject:entry mergeChanges:NO];
  76.  
  77.  
  78. i++;
  79. }
  80. }
Add Comment
Please, Sign In to add comment