How to fetch all contact on MacOS ?

Hello folks,

I'm trying to fetch all contact from MacOS using the contact frameworks, but the documentation doesn't explain how to do it.

So i'm searching for code in Swift or Objective-C (or anything else) to accomplish that.

Answered by DTS Engineer in 727003022

I need a function that return the list of all existing contact

That’s what they method does. Pass it a CNContactFetchRequest instance where the predicate property is set to nil. To quote the docs:

Set the value of this property to nil to match all contacts

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

You do this using CNContactStore. Once you’re authorised, call -enumerateContactsWithFetchRequest:error:usingBlock:.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for your reply, but that's not what i trying to do.

I need a function that return the list of all existing contact, and not fetching one specific contact.

Accepted Answer

I need a function that return the list of all existing contact

That’s what they method does. Pass it a CNContactFetchRequest instance where the predicate property is set to nil. To quote the docs:

Set the value of this property to nil to match all contacts

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How to fetch all contact on MacOS ?
 
 
Q