当按下show按钮时,如何在表格视图中获取重复的联系人?

时间:2018-04-28 09:17:59

标签: ios swift

这是尝试在我的函数中找到重复的方法

let keys = [CNContactIdentifierKey as CNKeyDescriptor, CNContactFormatter.descriptorForRequiredKeys(for: .fullName)]
let request = CNContactFetchRequest(keysToFetch: keys)
var contactsByName = [String: [CNContact]]()

在我打电话给do / catch

之后
do {
    try self.contactStore.enumerateContacts(with: request) { contact, stop in
        guard let name = CNContactFormatter.string(from: contact, style: .fullName) else { return }
        contactsByName[name] = (contactsByName[name] ?? []) + [contact]
    }
} catch let err {
    print("error:", err)
}

提前致谢

0 个答案:

没有答案