Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findDuplicateContacts not found #13

Closed
mitesh-iosdev opened this issue Nov 14, 2019 · 1 comment
Closed

findDuplicateContacts not found #13

mitesh-iosdev opened this issue Nov 14, 2019 · 1 comment

Comments

@mitesh-iosdev
Copy link

@satishbabariya & @vvit
I found findDuplicateContacts method in document but not in source file. Can you please add that method if missing?

@satishbabariya
Copy link
Collaborator

@mitesh-iosdev, try this old code, it may work.

public 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)
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants