Skip to content

Commit

Permalink
Minor Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
satishbabariya committed Dec 12, 2017
1 parent 40cddc4 commit 00ea885
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 42 deletions.
61 changes: 32 additions & 29 deletions SwiftyContacts/Classes/SwiftyContacts.swift
Expand Up @@ -56,6 +56,7 @@ public enum ContactsFetchResult {

/// Fetching Contacts from phone
/// - parameter completionHandler: Returns Either [CNContact] or Error.

public func fetchContacts( completionHandler : @escaping (_ result : ContactsFetchResult) -> ()){

let contactStore : CNContactStore = CNContactStore()
Expand All @@ -76,6 +77,7 @@ public func fetchContacts( completionHandler : @escaping (_ result : ContactsFet
/// - Parameters:
/// - sortOrder: To return contacts in a specific sort order.
/// - completionHandler: Result Handler
@available(iOS 10.0, *)
public func fetchContacts(ContactsSortorder sortOrder:CNContactSortOrder, completionHandler : @escaping (_ result : ContactsFetchResult) -> ()){

let contactStore : CNContactStore = CNContactStore()
Expand All @@ -96,35 +98,36 @@ public func fetchContacts(ContactsSortorder sortOrder:CNContactSortOrder, comple

/// etching Contacts from phone with Grouped By Alphabet
///
/// - Parameter completionHandler: It will return Dictonary of Alphabets with Their Sorted Respective Contacts
public func fetchContactsGroupedByAlphabets( completionHandler : @escaping (_ result : [String: [CNContact]],Error?) -> ()){

let fetchRequest: CNContactFetchRequest = CNContactFetchRequest(keysToFetch: [CNContactVCardSerialization.descriptorForRequiredKeys()])
var orderedContacts: [String: [CNContact]] = [String: [CNContact]]()
CNContact.localizedString(forKey: CNLabelPhoneNumberiPhone)
fetchRequest.mutableObjects = false
fetchRequest.unifyResults = true
fetchRequest.sortOrder = .givenName
do {
try CNContactStore().enumerateContacts(with: fetchRequest, usingBlock: { (contact, _) -> Void in
// Ordering contacts based on alphabets in firstname
var key: String = "#"
// If ordering has to be happening via family name change it here.
if let firstLetter = contact.givenName[0..<1], firstLetter.containsAlphabets() {
key = firstLetter.uppercased()
}
var contacts = [CNContact]()
if let segregatedContact = orderedContacts[key] {
contacts = segregatedContact
}
contacts.append(contact)
orderedContacts[key] = contacts
})
} catch {
completionHandler(orderedContacts, error)
}
completionHandler(orderedContacts,nil)
}
/// - Parameter completionHandler: It will return Dictonary of Alphabets with Their Sorted Respective Contacts.
//@available(iOS 10.0, *)
//public func fetchContactsGroupedByAlphabets( completionHandler : @escaping (_ result : [String: [CNContact]],Error?) -> ()){
//
// let fetchRequest: CNContactFetchRequest = CNContactFetchRequest(keysToFetch: [CNContactVCardSerialization.descriptorForRequiredKeys()])
// var orderedContacts: [String: [CNContact]] = [String: [CNContact]]()
// CNContact.localizedString(forKey: CNLabelPhoneNumberiPhone)
// fetchRequest.mutableObjects = false
// fetchRequest.unifyResults = true
// fetchRequest.sortOrder = .givenName
// do {
// try CNContactStore().enumerateContacts(with: fetchRequest, usingBlock: { (contact, _) -> Void in
// // Ordering contacts based on alphabets in firstname
// var key: String = "#"
// // If ordering has to be happening via family name change it here.
// if let firstLetter = contact.givenName[0..<1], firstLetter.containsAlphabets() {
// key = firstLetter.uppercased()
// }
// var contacts = [CNContact]()
// if let segregatedContact = orderedContacts[key] {
// contacts = segregatedContact
// }
// contacts.append(contact)
// orderedContacts[key] = contacts
// })
// } catch {
// completionHandler(orderedContacts, error)
// }
// completionHandler(orderedContacts,nil)
//}

/// Fetching Contacts from phone
/// - parameter completionHandler: Returns Either [CNContact] or Error.
Expand Down
6 changes: 3 additions & 3 deletions fastlane/README.md
Expand Up @@ -12,9 +12,9 @@ xcode-select --install

<table width="100%" >
<tr>
<th width="33%"><a href="http://brew.sh">Homebrew</a></td>
<th width="33%">Installer Script</td>
<th width="33%">Rubygems</td>
<th width="33%"><a href="http://brew.sh">Homebrew</a></th>
<th width="33%">Installer Script</th>
<th width="33%">RubyGems</th>
</tr>
<tr>
<td width="33%" align="center">macOS</td>
Expand Down
22 changes: 12 additions & 10 deletions fastlane/report.xml

Large diffs are not rendered by default.

0 comments on commit 00ea885

Please sign in to comment.