Returns a new array that lists the receiving array’s elements in ascending order as defined by the comparison function
- iOS 2.0+
- macOS 10.0+
- tvOS 9.0+
- watchOS 2.0+
- Mac Catalyst 13.0+Beta
The new array contains references to the receiving array’s elements, not copies of them.
The comparison function is used to compare two elements at a time and should return
NSOrdered if the first element is smaller than the second,
NSOrdered if the first element is larger than the second, and
NSOrdered if the elements are equal. Each time the comparison function is called, it’s passed
context as its third argument. This allows the comparison to be based on some outside parameter, such as whether character sorting is case-sensitive or case-insensitive.
an (an array of
NSNumber objects) and a comparison function of this type:
A sorted version of
an is created in this way: