Master data (SQLite supported) custom row sorting

I currently have a Core Data application that supports SQLite, where I retrieve records sorted by first name and then lastName.

The problem is that I have names like this (John Doe)and they go back to the top of the list, it seems the default sorting behavior is done in ASCII sort order.

Is there any way to make these entries appear after Z?

I read about custom sorting descriptors, but they don't seem to work because Core Data goes back to SQLite for sorting.

Update

Here is an example of a list of my data 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)
+3
5

BOOL parenthesized, ...

- (void)setName:(NSString *)name
{
    [self willChangeValueForKey:@"name"];
    [self setPrimitiveName:name];
    [self didChangeValueForKey:@"name"];
    self.parenthesized = ([name hasPrefix:@"("] &&
                          [name hasSuffix:@")"]);
}

:

[fetchRequest setSortDescriptors:
 [NSArray arrayWithObjects:
  [NSSortDescriptor sortDescriptorWithKey:@"parenthesized" ascending:NO],
  [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES],
  nil]];
+4

? , , ,

+1

SQLite. , , i-.

0

, /. ( iPhone).

order by replace(firstName, '(','')

, . , . ( ).

order by replace(firstName, '(','ZZZ')
0

when you perform the extraction of the main data, you return the array, sort the array using the comparison method (select): select (Select): Select (SEL): method. you can then write your own sort method that returns NSOrderAscending if the item is earlier, NSOrderDescending if it is later, and NSOrderSame if it is the same.

0
source

Source: https://habr.com/ru/post/1779286/


All Articles