sort(_:context:)
Sorts the receiver in ascending order as defined by the comparison function compare.
Declaration
func sort(_ compare: (Any, Any, UnsafeMutableRawPointer?) -> Int, context: UnsafeMutableRawPointer?)Parameters
- compare:
The comparison function to use to compare two elements at a time.
The function’s parameters are two objects to compare and the context parameter,
context. The function should returnNSOrderedAscendingif the first element is smaller than the second,NSOrderedDescendingif the first element is larger than the second, andNSOrderedSameif the elements are equal. - context:
The context argument to be passed to the compare function.
Discussion
This approach allows the comparison to be based on some outside parameter, such as whether character sorting is case sensitive or case insensitive.