Skip to content

Instantly share code, notes, and snippets.

@hngfu
Last active April 5, 2019 06:07
Show Gist options
  • Save hngfu/23fa7e4405b0810efd42b86957c8a515 to your computer and use it in GitHub Desktop.
Save hngfu/23fa7e4405b0810efd42b86957c8a515 to your computer and use it in GitHub Desktop.
다양한 조건을 걸어서 정렬하는 방법!
let familyNameSortDescriptor = NSSortDescriptor(key: CNContact.familyNameSortKey, ascending: true, selector: #selector(NSString.localizedStandardCompare(_:)))
let givenNameSortDescriptor = NSSortDescriptor(key: CNContact.givenNameSortKey, ascending: true, selector: #selector(NSString.localizedStandardCompare(_:)))
let sortDescriptors = [familyNameSortDescriptor, givenNameSortDescriptor]
let sortedContacts = (contacts as NSArray).sortedArray(using: sortDescriptors)
guard let contacts = sortedContacts as? [CNContact] else { return }
self.contacts = contacts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment