Returns an array that lists the receiving array’s elements in ascending order, as determined by the comparison method specified by a given selector.
- iOS 2.0+
- macOS 10.0+
- tvOS 9.0+
- watchOS 2.0+
- Mac Catalyst 13.0+Beta
A selector that identifies the method to use to compare two elements at a time. The method should return
NSOrderedif the receiving array is smaller than the argument,
NSOrderedif the receiving array is larger than the argument, and
NSOrderedif they are equal.
An array that lists the receiving array’s elements in ascending order, as determined by the comparison method specified by the selector
The new array contains references to the receiving array’s elements, not copies of them.
comparator message is sent to each object in the array and has as its single argument another object in the array.
For example, an array of
NSString objects can be sorted by using the
case method declared in the
NSString class. Assuming
an exists, a sorted version of the array can be created in this way: