Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSFetchRequest *oldFetchRequest = [[NSFetchRequest alloc] init];
- NSEntityDescription *oldEntryEntity = [NSEntityDescription entityForName:@"Entry"
- inManagedObjectContext:oldContext];
- [oldFetchRequest setEntity:oldEntryEntity];
- [oldFetchRequest setFetchBatchSize:10];
- [oldFetchRequest setIncludesPropertyValues:NO];
- NSArray *entrys = [oldContext executeFetchRequest:oldFetchRequest error:&error];
- int totalEntries = [oldContext countForFetchRequest:oldFetchRequest error:nil];
- int i = 0;
- while (i < totalEntries) {
- @autoreleasepool {
- Entry *entry = [entrys objectAtIndex:i];
- NSLog(@"message 1: %@", [entry valueForKey:@"message"]);
- [oldContext reset];
- i++;
- }
- }
- NSFetchRequest *oldFetchRequest = [[NSFetchRequest alloc] init];
- NSEntityDescription *oldEntryEntity =
- [NSEntityDescription entityForName:@"Entry"
- inManagedObjectContext:oldContext];
- [oldFetchRequest setEntity:oldEntryEntity];
- [oldFetchRequest setFetchBatchSize:10];
- [oldFetchRequest setIncludesPropertyValues:NO];
- NSArray *entrys = [oldContext executeFetchRequest:oldFetchRequest error:&error];
- int totalEntries = [oldContext countForFetchRequest:oldFetchRequest error:nil];
- NSLog(@"entrys count = %u", entrys.count);
- for (NSManagedObject *entry in entrys) {
- NSLog(@"entry: %@", entry);
- }
- int i = 0;
- while (i < totalEntries) {
- @autoreleasepool {
- // You get the i-th entry. It will be a managed object. It could be a fault
- // or it could be a fully hydrated object. Based on your batch size, the
- // first ten (0 <= i < 10) will be complete objects.
- Entry *entry = [entrys objectAtIndex:i];
- // Log the "message" attribute. By calling valueForKey, the object will be
- // faulted into memory if it is a fault. Since your batch size is 10,
- // this will make sure 10 objects are faulted if one is needed.
- NSLog(@"message 1: %@", [entry valueForKey:@"message"]);
- // Resetting the entire context blows away everything in the context.
- // Calling reset is a hard call, and should not be done if you have
- // references to the objects in the context.
- [oldContext reset];
- i++;
- }
- }
- - (void)refreshObject:(NSManagedObject *)object mergeChanges:(BOOL)flag
- while (i < totalEntries) {
- @autoreleasepool {
- Entry *entry = [entrys objectAtIndex:i];
- NSLog(@"message 1: %@", [entry valueForKey:@"message"]);
- [oldContext refreshObject:entry mergeChanges:NO];
- i++;
- }
- }
Add Comment
Please, Sign In to add comment