Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 17th, 2010  |  syntax: Objective C  |  size: 1.70 KB  |  views: 35  |  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.     - (NSFetchedResultsController *)fetchedResultsController {
  2.        
  3.         if (fetchedResultsController != nil) {
  4.             return fetchedResultsController;
  5.         }
  6.    
  7.         /*
  8.          Set up the fetched results controller.
  9.          */
  10.         // Create the fetch request for the entity.
  11.         NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
  12.         // Edit the entity name as appropriate.
  13.         NSEntityDescription *entity = [NSEntityDescription entityForName:@"Reminder" inManagedObjectContext:managedObjectContext];
  14.         [fetchRequest setEntity:entity];
  15.        
  16.         // Set the batch size to a suitable number.
  17.         [fetchRequest setFetchBatchSize:20];
  18.        
  19.         // Edit the sort key as appropriate.
  20.         NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"textContent" ascending:NO];
  21.         NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
  22.        
  23.         [fetchRequest setSortDescriptors:sortDescriptors];
  24.        
  25.         // Edit the section name key path and cache name if appropriate.
  26.         // nil for section name key path means "no sections".
  27.         NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
  28.         aFetchedResultsController.delegate = self;
  29.         self.fetchedResultsController = aFetchedResultsController;
  30.        
  31.         [aFetchedResultsController release];
  32.         [fetchRequest release];
  33.         [sortDescriptor release];
  34.         [sortDescriptors release];
  35.        
  36.         return fetchedResultsController;
  37.     }
clone this paste RAW Paste Data