So i have the following code:
NSArray *pathArray = @[@"path/Documents/page9.png",
@"path/Documents/page8.png",
@"path/Documents/page10.png",
@"path/Documents/page11.png",
@"path/Documents/page0.png",
@"path/Documents/page12.png",
@"path/Documents/page6.png",
@"path/Documents/page4.png",
@"path/Documents/page5.png",
@"path/Documents/page1.png",
@"path/Documents/page7.png",
@"path/Documents/page3.png",
@"path/Documents/page2.png"];
If I now sort the array using:
[pathArray sortUsingSelector:@selector(caseInsensitiveCompare:)];
The Array is sorted the wrong way
Result:
pathArray: (
"path/Documents/page0.png",
"path/Documents/page1.png",
"path/Documents/page10.png",
"path/Documents/page11.png",
"path/Documents/page12.png",
"path/Documents/page2.png",
"path/Documents/page3.png",
"path/Documents/page4.png",
"path/Documents/page5.png",
"path/Documents/page6.png",
"path/Documents/page7.png",
"path/Documents/page8.png",
"path/Documents/page9.png"}
The elements with the components "page10.png", "page11.png" and "page12.png" should be the last three elements. Does another selector exist that covers this issue?
If not how could this be done?
You can implement your own comparing method using this:
[pathArray sortUsingComparator:^(id one, id two) {
return [one compare:two options:NSCaseInsensitiveSearch | NSNumericSearch];
}
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