Write a custom sorting function:
NSInteger customSortingFunctionReversedAndNumericFirst(NSString *string1, NSString *string2, void *context) {
NSCharacterSet *decimalCharacterSet;
BOOL firstStringStartsWithNumeric,
secondStringStartsWithNumeric;
decimalCharacterSet = [NSCharacterSet decimalDigitCharacterSet];
firstStringStartsWithNumeric = [decimalCharacterSet characterIsMember:[string1 characterAtIndex:0]];
secondStringStartsWithNumeric = [decimalCharacterSet characterIsMember:[string2 characterAtIndex:0]];
if (firstStringStartsWithNumeric != secondStringStartsWithNumeric) {
return firstStringStartsWithNumeric ? NSOrderedAscending : NSOrderedDescending;
}
return [string2 compare:string1 options:NSNumericSearch];
}
and use it like this:
NSArray *sortedDirectoryContent = [directoryContent sortedArrayUsingFunction:customSortingFunctionReversedAndNumericFirst context:NULL]
I have made many assumption, but this code works on your sample array and similar input values.
The main assumption is that you wanted this particular order only for strings that start with a numeric value. If it's not the case, you can use this code to adapt it to the algorithm you want.