Is there a way I can fetch contacts using the Contacts framework without an attribute?
Example:
myContactArray = unifiedContactsNotCalled("John")
PS: I know that line is nothing like the real code, it's just a serving suggestion for illustrative purposes
Before I outline how to find those that don't match a name, let's recap how one finds those that do. In short, you'd use a predicate:
(Obviously, you'd wrap that in a
do
-try
-catch
construct, or whatever error handling pattern you want.)Unfortunately, you cannot use your own custom predicates with the Contacts framework, but rather can only use the
CNContact
predefined predicates. Thus, if you want to find contacts whose name does not contain "John", you have to manuallyenumerateContacts(with:)
and build your results from that: