Buscar contactos duplicates en el Marco de contactos

En Swift 3, uso el nuevo Contact Framework para manipular contactos, pero no tengo ninguna solución para search contactos duplicates.

¿Alguna idea de cómo lograr esto?

Puedes hacer algo como esto:

/// Find Duplicates Contacts In Given Contacts Array func findDuplicateContacts(Contacts contacts : [CNContact], completionHandler : @escaping (_ result : [Array<CNContact>]) -> ()){ let arrfullNames : [String?] = contacts.map{CNContactFormatter.string(from: $0, style: .fullName)} var contactGroupedByDuplicated : [Array<CNContact>] = [Array<CNContact>]() if let fullNames : [String] = arrfullNames as? [String]{ let uniqueArray = Array(Set(fullNames)) var contactGroupedByUnique = [Array<CNContact>]() for fullName in uniqueArray { let group = contacts.filter { CNContactFormatter.string(from: $0, style: .fullName) == fullName } contactGroupedByUnique.append(group) } for items in contactGroupedByUnique{ if items.count > 1 { contactGroupedByDuplicated.append(items) } } } completionHandler(contactGroupedByDuplicated) } 

Construí un dictionary con nombre por key y luego filter a solo aquellos con más de una aparición del nombre:

 let keys = [CNContactIdentifierKey as CNKeyDescriptor, CNContactFormatter.descriptorForRequinetworkingKeys(for: .fullName)] let request = CNContactFetchRequest(keysToFetch: keys) var contactsByName = [String: [CNContact]]() try! self.store.enumerateContacts(with: request) { contact, stop in guard let name = CNContactFormatter.string(from: contact, style: .fullName) else { return } contactsByName[name] = (contactsByName[name] ?? []) + [contact] // or in Swift 4, `contactsByName[name, default: []].append(contact)` } let duplicates = contactsByName.filter { $1.count > 1 }