Fix ordering of contacts picker.

pull/1/head
Matthew Chen 7 years ago
parent bef2e7b5c8
commit 1a2d10d2cc

@ -196,13 +196,20 @@ public class ContactsPicker: OWSViewController, UITableViewDelegate, UITableView
} }
func collatedContacts(_ contacts: [CNContact]) -> [[CNContact]] { 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) var collated = Array(repeating: [CNContact](), count: collation.sectionTitles.count)
for contact in contacts { for contact in contacts {
let sectionNumber = collation.section(for: contact, collationStringSelector: selector) let sectionNumber = collation.section(for: contact,
collationStringSelector: sortSelector)
collated[sectionNumber].append(contact) 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 return collated
} }
@ -365,7 +372,7 @@ fileprivate extension CNContact {
@objc var nameForCollating: String { @objc var nameForCollating: String {
get { get {
if self.familyName.isEmpty && self.givenName.isEmpty { 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 let compositeName: String
@ -374,7 +381,7 @@ fileprivate extension CNContact {
} else { } else {
compositeName = "\(self.givenName) \(self.familyName)" compositeName = "\(self.givenName) \(self.familyName)"
} }
return compositeName.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) return compositeName.lowercased().ows_stripped()
} }
} }
} }

Loading…
Cancel
Save