MDQuerySetSortComparatorBlock(_:_:)
Sets the block used to sort the results of an MDQuery.
Declaration
func MDQuerySetSortComparatorBlock(_ query: MDQuery!, _ comparator: ((UnsafePointer<Unmanaged<CFTypeRef>?>?, UnsafePointer<Unmanaged<CFTypeRef>?>?) -> CFComparisonResult)!)Parameters
- query:
The query.
- comparator:
The callback block the MDQuery will use to sort its results. The comparator may be called on multiple threads in parallel, and must be reentrant. To take advantage of parallel sorting, it is best to avoid any locking in the comparator.
The block may be
NULLto cancel any custom comparator.
Discussion
You may set the comparator block as many times as you like, even while the query is executing. Whenever the comparator block is set, all results are re-sorted using the new comparator block before the function returns. The block can be NULL to cancel custom sorting and revert to the default sorting.
The default sort provided by MDQueryCreate(_:_:_:_:) is an ascending sort. Strings are compared using CFStringCompare(_:_:_:) with the options compareNonliteral | compareLocalized | compareNumerically. CFDataRefs are compared by using memcmp() of the data pointers.