I currently have a SQLite backed Core Data app where I am fetching records sorted on firstName and then lastName.
The issue is that I have some names like (John Doe) and they are coming back at the top of the list, it seems the default sorting behavior is done in ASCII sort order.
Is there anyway to force these records to show up after Z?
I have read about custom sort descriptors but they do not seem to work because Core Data falls back on SQLite for sorting.
Update
Here is a sample list of what my data looks like now
(Abe Simpson)
(Bob Dole)
(Chris Rock)
Alan West
Brian Regan
What I want it to look like
Alan West
Brian Regan
(Abe Simpson)
(Bob Dole)
(Chris Rock)
Add a new BOOL attribute called parenthesized, then...
- (void)setName:(NSString *)name
{
[self willChangeValueForKey:@"name"];
[self setPrimitiveName:name];
[self didChangeValueForKey:@"name"];
self.parenthesized = ([name hasPrefix:@"("] &&
[name hasSuffix:@")"]);
}
And when you do the fetch:
[fetchRequest setSortDescriptors:
[NSArray arrayWithObjects:
[NSSortDescriptor sortDescriptorWithKey:@"parenthesized" ascending:NO],
[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES],
nil]];
What is the reason for the parenthesis ? You could probably make things easier for yourself if you replaced this implicit information with explicit information in a separate property that can then be used to direct sorting
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With