I did find duplicate contacts list from this method , now i'm stuck in merging the duplicates, any idea how i can do this.
I fetched duplicate using this code Referenced from previous question.
let formatter = CNContactFormatter()
formatter.style = .fullName
let keys = [CNContactIdentifierKey as CNKeyDescriptor, CNContactFormatter.descriptorForRequiredKeys(for: .fullName)]
let request = CNContactFetchRequest(keysToFetch: keys)
var contactsByName = [String: [CNContact]]()
try! self.store.enumerateContacts(with: request) { contact, stop in
guard let name = formatter.string(from: contact) else { return }
contactsByName[name] = (contactsByName[name] ?? []) + [contact] // or in Swift 4, `contactsByName[name, default: []].append(contact)`
}
let duplicates = contactsByName.filter { $1.count > 1 }
If you followed my previous answer for fetching duplicates list after you can use this code to merge duplicates.
This approach will take quite a memory so I suggest, use this approach as a reference.