I have an NSArrayController and I would like to sort the contents so that anything with English alphabets are sorted first and then anything with numbers and non English characters are sorted last.
For example: A, B , C … Z, 1 , 2, 3 … 9, 구, 결, …
Currently I only know how to sort items in alphabetical order. Suggestions?
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
[dataController setSortDescriptors: [NSArray arrayWithObject: sort]];
You can use
sortedArrayUsingComparatorto customize the sort algorithm to your needs. For instance, you can give precedence to symbols with this lines:To put English characters before non-English ones, it’d be enough to use
NSDiacriticInsensitiveSearch | NSCaseInsensitiveSearchas options, no fancy algorithm required.If you need to support iOS without blocks try
sortedArrayUsingSelector.