|
|
|
@ -196,13 +196,20 @@ public class ContactsPicker: OWSViewController, UITableViewDelegate, UITableView
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collatedContacts(_ contacts: [CNContact]) -> [[CNContact]] {
|
|
|
|
|
let selector: Selector = #selector(getter: CNContact.nameForCollating)
|
|
|
|
|
let sortSelector = #selector(getter: CNContact.nameForCollating)
|
|
|
|
|
|
|
|
|
|
// 1. Organize the contacts into sections.
|
|
|
|
|
var collated = Array(repeating: [CNContact](), count: collation.sectionTitles.count)
|
|
|
|
|
for contact in contacts {
|
|
|
|
|
let sectionNumber = collation.section(for: contact, collationStringSelector: selector)
|
|
|
|
|
let sectionNumber = collation.section(for: contact,
|
|
|
|
|
collationStringSelector: sortSelector)
|
|
|
|
|
collated[sectionNumber].append(contact)
|
|
|
|
|
}
|
|
|
|
|
// 2. Sort the contents of each section.
|
|
|
|
|
collated = collated.map({ (sectionContacts) in
|
|
|
|
|
return collation.sortedArray(from: sectionContacts,
|
|
|
|
|
collationStringSelector: sortSelector)
|
|
|
|
|
}) as! [[CNContact]]
|
|
|
|
|
return collated
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -365,7 +372,7 @@ fileprivate extension CNContact {
|
|
|
|
|
@objc var nameForCollating: String {
|
|
|
|
|
get {
|
|
|
|
|
if self.familyName.isEmpty && self.givenName.isEmpty {
|
|
|
|
|
return self.emailAddresses.first?.value as String? ?? ""
|
|
|
|
|
return (self.emailAddresses.first?.value as String? ?? "").lowercased().ows_stripped()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let compositeName: String
|
|
|
|
@ -374,7 +381,7 @@ fileprivate extension CNContact {
|
|
|
|
|
} else {
|
|
|
|
|
compositeName = "\(self.givenName) \(self.familyName)"
|
|
|
|
|
}
|
|
|
|
|
return compositeName.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
|
|
|
|
|
return compositeName.lowercased().ows_stripped()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|