Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user sort order with CNContact API

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.

like image 311
Andrew Duncan Avatar asked Oct 14 '15 23:10

Andrew Duncan


2 Answers

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

let sortOrder = CNContactsUserDefaults.sharedDefaults().sortOrder

like image 103
Ken Avatar answered Oct 22 '22 17:10

Ken


Swift 4

Using the default sort Order :

let sortOrder = CNContactsUserDefaults.shared().sortOrder

For Custom Sort Order i.e.

let customSortOrder = CNContactSortOrder.givenName
like image 39
Md. Ibrahim Hassan Avatar answered Oct 22 '22 18:10

Md. Ibrahim Hassan