UA-17470720-3

Jump to content


Photo
- - - - -

case-insensitive sorting - revisited

sections

  • Please log in to reply
2 replies to this topic

#1 Dennis

Dennis

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 23 posts
Reputation: 4
Good

Posted 09 August 2016 - 09:48 PM

Hi 

 

When using the dataFetchOptions to sort a section...

 

 

self.tableModel.dataFetchOptions.sort = YES;

self.tableModel.dataFetchOptions.sortAscending = YES;
self.tableModel.dataFetchOptions.sortKey = @"title";
 
...results in a sortDescriptor using the compare: selector
 
 
self.tableModel.dataFetchOptions.sortDescriptors NSArray: (title, ascending, compare:)
 
 
I would like to set up the sortDescriptor to use the caseInsensitiveCompare: selector.
How can I do that?
 
 
NB: I am a aware I can also sort the items myself in section.sectionActions.didFetchItemsFromStore, but that would mean having to change a quite a lot of code. I would be *much* more straightforward to be able to set the sortDescriptor (or its compare selector) on the dataFetchOptions.
 
Thanks
Dennis
 
 
 
 


#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 443
Popular

Posted 10 August 2016 - 10:06 AM

Hi Dennis,

 

The current way to further customize sorting, other than implementing 'didFetchItemsFromStore', is to subclass your relevant data fetch options class and provide your own custom 'sortDescriptors' method override. For instance, if you're working with SCCoreDataFetchOptions:

 

@interface MyFetchOptions : SCCoreDataFetchOptions
@end

@implementation MyFetchOptions
- (NSArray *)sortDescriptors
{
  return myCustomDescriptors;
}
@end


...
// later in your ViewController
...

SCCoreDataFetchOptions *oldOptions = myArrayOfObjectsSection.dataFetchOptions;
MyFetchOptions *myFetchOptions = [MyFetchOptions optionsWithSortKey:oldOptions.sortKey sortAscending:YES filterPredicate:nil];
myFetchOptions.orderAttributeName = oldOptions.orderAttributeName; // only required if you're setting 'orderAttributeName'
myArrayOfObjectsSection.dataFetchOptions = myFetchOptions;

Edited by Tarek, 10 August 2016 - 10:09 AM.
Fixed typo

  • wizgod likes this

#3 Dennis

Dennis

    Jr. Member

  • STV 5.0 Pro
  • PipPip
  • 23 posts
Reputation: 4
Good

Posted 25 September 2016 - 11:24 AM

Many, thanks. Will try that  (somehow missed your reply). 

 

Edit: That took 5 minutes and works perfectly!

 

Dennis


Edited by Dennis, 25 September 2016 - 11:39 AM.






Also tagged with one or more of these keywords: sections

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users