diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d96fed7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +ContactsApp.xcodeproj/xcuserdata/user.xcuserdatad/xcdebugger/ diff --git a/ContactsApp.xcodeproj/project.pbxproj b/ContactsApp.xcodeproj/project.pbxproj index 9aed019..eb025b2 100644 --- a/ContactsApp.xcodeproj/project.pbxproj +++ b/ContactsApp.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ CE3351F3241A65D400BA57CA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F1241A65D400BA57CA /* Main.storyboard */; }; CE3351F5241A65D500BA57CA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F4241A65D500BA57CA /* Assets.xcassets */; }; CE3351F8241A65D500BA57CA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F6241A65D500BA57CA /* LaunchScreen.storyboard */; }; + CEC259D8241FAC79005237F5 /* File.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC259D7241FAC79005237F5 /* File.swift */; }; CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */; }; CEC9A381241C096D00F024EE /* SingleContactViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC9A380241C096D00F024EE /* SingleContactViewController.swift */; }; /* End PBXBuildFile section */ @@ -24,6 +25,7 @@ CE3351F4241A65D500BA57CA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; CE3351F7241A65D500BA57CA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; CE3351F9241A65D500BA57CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + CEC259D7241FAC79005237F5 /* File.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = ""; }; CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactsViewController.swift; sourceTree = ""; }; CEC9A380241C096D00F024EE /* SingleContactViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleContactViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -66,6 +68,7 @@ CE3351F9241A65D500BA57CA /* Info.plist */, CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */, CEC9A380241C096D00F024EE /* SingleContactViewController.swift */, + CEC259D7241FAC79005237F5 /* File.swift */, ); path = ContactsApp; sourceTree = ""; @@ -141,6 +144,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CEC259D8241FAC79005237F5 /* File.swift in Sources */, CE3351EC241A65D400BA57CA /* AppDelegate.swift in Sources */, CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */, CE3351EE241A65D400BA57CA /* SceneDelegate.swift in Sources */, diff --git a/ContactsApp.xcodeproj/xcuserdata/user.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ContactsApp.xcodeproj/xcuserdata/user.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist deleted file mode 100644 index 1daeed1..0000000 --- a/ContactsApp.xcodeproj/xcuserdata/user.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - diff --git a/ContactsApp/ContactsViewController.swift b/ContactsApp/ContactsViewController.swift index 3b689df..bb21000 100644 --- a/ContactsApp/ContactsViewController.swift +++ b/ContactsApp/ContactsViewController.swift @@ -14,6 +14,7 @@ class ContactsViewController: UIViewController { @IBOutlet weak var contactsTable: UITableView! var contacts = [CNContact]() + var contactsBackup = [CNContact]() let contactStore = CNContactStore() override func viewDidLoad() { @@ -24,9 +25,8 @@ class ContactsViewController: UIViewController { func importContacts() { - let keys = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName)] - //obtengo - let request = CNContactFetchRequest(keysToFetch: keys) + let keys = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName), CNContactEmailAddressesKey, CNContactPhoneNumbersKey, CNContactImageDataKey, CNContactImageDataAvailableKey] as [Any] + let request = CNContactFetchRequest( keysToFetch: keys as! [CNKeyDescriptor]) request.sortOrder = CNContactSortOrder.givenName do { try self.contactStore.enumerateContacts(with: request) { @@ -66,5 +66,31 @@ extension ContactsViewController: UITableViewDelegate, UITableViewDataSource { performSegue(withIdentifier: "gotocontact", sender: selectedContact) } - + func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat { + return 40 + } + + func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + let button = UIButton(type: .system) + button.setTitle("Λ", for: .normal) + button.setTitleColor(.black, for: .normal) + button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 15) + button.backgroundColor = .systemGray4 + button.addTarget(self, action: #selector(closeSection), for: .touchUpInside) + + return button//ʌΛ + } + + @objc func closeSection() { + contactsBackup = contacts + let section = 0 + + var indexPaths = [IndexPath]() + for row in contacts.indices { + let indexPath = IndexPath(row: row, section: section) + indexPaths.append(indexPath) + } + contacts.removeAll() + contactsTable.reloadData() + } } diff --git a/ContactsApp/File.swift b/ContactsApp/File.swift new file mode 100644 index 0000000..31d1485 --- /dev/null +++ b/ContactsApp/File.swift @@ -0,0 +1,13 @@ +// +// File.swift +// ContactsApp +// +// Created by User on 3/16/20. +// Copyright © 2020 jheisecke. All rights reserved. +// + +import Foundation + +class Contacts { + +} diff --git a/ContactsApp/SingleContactViewController.swift b/ContactsApp/SingleContactViewController.swift index a50014b..3a71d15 100644 --- a/ContactsApp/SingleContactViewController.swift +++ b/ContactsApp/SingleContactViewController.swift @@ -21,7 +21,7 @@ class SingleContactViewController: UIViewController { if let contact = selectedContact{ title = "\(contact.givenName) \(contact.familyName)" contactFullname.text = "\(contact.givenName) \(contact.familyName)" - phoneNumber.text = contact.phoneNumbers.description + //phoneNumber.text = CNLabeledValue.localizedStringForLabel(contact.phoneNumbers) if contact.imageDataAvailable { if let image = contact.imageData {