title: nsfetchedresultscontroller sort sections base on item count
body: <p>I use the code below to do a fetch result from <code>branch</code> table in a country:</p>
  
  <pre><code>- (NSFetchedResultsController *)fetchedResultsController
  {
      if (_fetchedResultsController != nil)
      {
          return _fetchedResultsController;
      }
  
      NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
      NSEntityDescription *entity = [NSEntityDescription entityForName:@"BranchData" inManagedObjectContext:[BRCoreRepository instance].managedObjectContext];
      [fetchRequest setEntity:entity];
  
      [fetchRequest setFetchBatchSize:5];
  
      NSString *cache = nil;
  
      if (searchValue.length &gt; 0){
          fetchRequest.predicate =[NSPredicate predicateWithFormat:@" city contains[cd] %@ || address contains[cd] %@ || branchCode contains[cd] %@ ",searchValue,searchValue,searchValue];
      } else cache = @"_preditc_state";
  
      NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"branchState" ascending:YES];
      [fetchRequest setSortDescriptors:@[sortDescriptor ]];
  
      _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
                                                                      managedObjectContext:[BRCoreRepository instance].managedObjectContext
                                                                        sectionNameKeyPath:@"branchState"
                                                                                 cacheName:cache
                                   ];
      _fetchedResultsController.delegate = self;
  
      return _fetchedResultsController;
  }
  </code></pre>
  
  <p>In the current code I could create sections based on the <code>branchState</code> of the branch. It is working correctly, but I have another problem - I want to order the items based on section item count too. So if in state <code>B</code> we have 200 items but in section <code>A</code> we have 150 items in the result we would show section <code>B</code> above section <code>A</code>. Is this possible with <code>NSFetchedResultsController</code> too?</p>