NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Import and check contacts

Forums > Swift

I have an app where I import the contacts from the Contacts app. All that works just fine.

Heres the scenario, if the user taps the button to import contacts into the app and then he/she adds a couple new contacts to their Contacts app. When they reimport, I get duplicate entries. Is there a good way to make sure that the same contact doesn't get imported twice?



I don't know if there is a good way. But it's your responsibility to check if a contact has been already imported. We don't know how you store the imported contacts and if there is an unique identifier for your stored contacts.

All I can say is that there is an identifier for each contact. So basically, you could check for the identifier and make sure it isn't already in your database.



Thank you, I'll add that to my Core Data model and check it before loading new contacts.


Seems like redundant work to write code to exclude duplicate records.

Restricting data sets with unique identifiers is a fundamental function in data storage services, Core Data included.

@twoStraws wrote an article about this.

See --> Core Data Constraints


Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until October 1st.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.