Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Currently I have a solution for that, but not a clean one:<br> I want to batch unfault by groups of 20, in an ordered relationship.</p> <p>So, every time i address an index that its index divides by 20 (index % 20 == 0), I use a new NSFetchRequest for the next 20 and unfault them by calling a common field name.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row % 20 == 0) { NSArray *objectsToUnfault = [[someObject.orderedRelationship array] subarrayWithRange:NSMakeRange(indexPath.row, MIN(20, [someObject.orderedRelationship count] - indexPath.row))]; // It's important to hold on this array, otherwise objects fault back self.lastPrefetch = [self preFetchEntityOfClass:[Post class] faultObjects:objectsToUnfault error:&amp;error]; } //... continue and create cell } - (NSArray *)preFetchEntityOfClass:(Class)entityClass faultObjects:(NSArray*)objects error:(NSError **)error { NSEntityDescription *entityDescription = [NSEntityDescription entityForName:NSStringFromClass(entityClass) inManagedObjectContext:self.managedObjectContext]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF in %@", objects]; NSFetchRequest *request = [[NSFetchRequest alloc] init]; [request setEntity:entityDescription]; [request setPredicate:predicate]; [request setFetchBatchSize:MIN([objects count], 20)]; NSArray *results = [self.managedObjectContext executeFetchRequest:request error:error]; // I assume all my objects has this field "uid" NSArray *resultsUid = [results valueForKey:@"uid"]; //Batch unfaulting (results is a BatchFaultArray, private class type) if ([resultsUid count] != [results count]) { NSLog(@"Error: wrong count of uids"); //We need to use resultsUid, to avoid compiler opt } return results; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload