Respond to CR.

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

@ -185,6 +185,7 @@ public class ContactsPicker: OWSViewController, UITableViewDelegate, UITableView
do { do {
let contactFetchRequest = CNContactFetchRequest(keysToFetch: allowedContactKeys) let contactFetchRequest = CNContactFetchRequest(keysToFetch: allowedContactKeys)
contactFetchRequest.sortOrder = .userDefault
try contactStore.enumerateContacts(with: contactFetchRequest) { (contact, _) -> Void in try contactStore.enumerateContacts(with: contactFetchRequest) { (contact, _) -> Void in
contacts.append(contact) contacts.append(contact)
} }
@ -196,20 +197,13 @@ public class ContactsPicker: OWSViewController, UITableViewDelegate, UITableView
} }
func collatedContacts(_ contacts: [CNContact]) -> [[CNContact]] { func collatedContacts(_ contacts: [CNContact]) -> [[CNContact]] {
let sortSelector = #selector(getter: CNContact.nameForCollating) let selector: Selector = #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, let sectionNumber = collation.section(for: contact, collationStringSelector: selector)
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
} }
@ -372,7 +366,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? ?? "").lowercased().ows_stripped() return self.emailAddresses.first?.value as String? ?? ""
} }
let compositeName: String let compositeName: String
@ -381,7 +375,7 @@ fileprivate extension CNContact {
} else { } else {
compositeName = "\(self.givenName) \(self.familyName)" compositeName = "\(self.givenName) \(self.familyName)"
} }
return compositeName.lowercased().ows_stripped() return compositeName.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
} }
} }
} }

Loading…
Cancel
Save