How to reverse-sort a file list using Objective-C?
sortUsingComparator is Method to sort an array.
Sorting is according to NSComparisonResult of the block function parameter.
Let’s see the example to sort file list.
If the returned NSComparisonResult is NSOrderedAscending or NSOrderedSame, it does nothing. But if it is NSOrderedDescending, the position of element will be swapped. In other word, it is sorted in ascending order by default.
But how do I sort reverse it, descending order by?
First, let’s see definition of NSComparisonResult
it can be implemented with if sentence, but assuming the above definition is immutable, it can be implemented as follows.
Just multiply by -1 to it, the result will be reversed.
#배열 #역정렬 #Array #Descending #Reverse