UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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?

Thanks

2      

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.

2      

@Hatsushira

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

2      

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

2      

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 April 28th.

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.