In Objective-C, I'd sort an array of people as follows:
CFArraySortValues(mutablePeople,
CFRangeMake(0, CFArrayGetCount(mutablePeople)),
(CFComparatorFunction) ABPersonComparePeopleByName,
kABPersonSortByFirstName)
I'm struggling to figure out how to do the same in Swift. The following:
let ctx = UnsafeMutablePointer<Void>.alloc(kABPersonSortByFirstName)
CFArraySortValues(mutablePeople,
CFRangeMake(0, CFArrayGetCount(mutablePeople)),
ABPersonComparePeopleByName,
ctx)
Gives compilation error:
Cannot invoke 'CFArraySortValues' with an argument list of type '(CFMutableArray!, CFRange, (ABRecord!, ABRecord!, ABPersonSortOrdering) -> CFComparisonResult, UnsafeMutablePointer)'
The problem looks to be with the ABPersonComparePeopleByName
which would be cast to a CFComparatorFunction
in Objective-C.