I would like to store data in the contact store that is part of CNContact. Is there a property of NSObject or CNContact that I can store the contents of a Data structure or NSDate object? I would like to be able to keep up with when a CNContact was last modified.
I haven't found anything way that Apple has given us to specifically do this. I don't want to save the date of modification in UserDefaults or CloudKit or Core Data or any other way of persisting data. I don't want to use the Note property of CNContact, since it would be able to be changed by the user. The dates instance property of CNContact is get only, and I haven't found any way of using that property to do what I want to do.
An alternative would be to compare hash values or to us the isEqual method of CNContact or use the === or == operators. Would that work?
There seem to be an issue with
CNContactStoreand enumeratorForChangeHistoryFetchRequest:error: is not available in Swift.It is possible to wrap an instance of
CNContactStorein an Objective-C class :ContactStoreWrapper.h
ContactStoreWrapper.m
Synchronizing access to contacts
Next I created an actor in order to synchronize contacts updates :
Visitor
And a visitor, conforming to
CNChangeHistoryEventVisitor, to responds to history events and updates the actor.Fetching Contact History
Then I created a small helper class in Swift to fetch the history changes, and responds to external changes of the contact store using
CNContactStoreDidChange:UI
Now we can display the result in a simple view