10

I know that I can sort with CNContacts like this:

let fetch = CNContactFetchRequest(...)
fetch.sortOrder = .UserDefault

The question is: how do I find what is that sort order? Apart from some hacky heuristic of examining what comes back from the fetch enumeration.

There is an old ABPersonGetSortOrdering() call that will probably stay around for a while, but surely there is a CNContact way to do it.

Md. Ibrahim Hassan
  • 5,359
  • 1
  • 25
  • 45
Andrew Duncan
  • 3,553
  • 4
  • 28
  • 55

2 Answers2

14

ABPersonGetSortOrdering() was deprecated in iOS 9.0: use [[CNContactsUserDefaults sharedDefaults] sortOrder]

let sortOrder = CNContactsUserDefaults.sharedDefaults().sortOrder

Marco
  • 6,692
  • 2
  • 27
  • 38
Ken
  • 773
  • 1
  • 9
  • 17
  • 1
    This really works, thanks! Just wondering that CNContactsUserDefaults is not properly documented. I hope it's not an internal API? – Nick Entin Jan 11 '16 at 14:35
  • It's not: https://developer.apple.com/documentation/contacts/cncontactsuserdefaults/1402779-sortorder – jamix Jul 01 '19 at 20:37
5

Swift 4

Using the default sort Order :

let sortOrder = CNContactsUserDefaults.shared().sortOrder

For Custom Sort Order i.e.

let customSortOrder = CNContactSortOrder.givenName
Md. Ibrahim Hassan
  • 5,359
  • 1
  • 25
  • 45