Commit 88cbd54a by Javier Heisekce

Se colapsa los contactos

parent 92cc2d0f
ContactsApp.xcodeproj/xcuserdata/user.xcuserdatad/xcdebugger/
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
CE3351F3241A65D400BA57CA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F1241A65D400BA57CA /* Main.storyboard */; }; CE3351F3241A65D400BA57CA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F1241A65D400BA57CA /* Main.storyboard */; };
CE3351F5241A65D500BA57CA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F4241A65D500BA57CA /* Assets.xcassets */; }; CE3351F5241A65D500BA57CA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F4241A65D500BA57CA /* Assets.xcassets */; };
CE3351F8241A65D500BA57CA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE3351F6241A65D500BA57CA /* LaunchScreen.storyboard */; }; 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 */; }; CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */; };
CEC9A381241C096D00F024EE /* SingleContactViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC9A380241C096D00F024EE /* SingleContactViewController.swift */; }; CEC9A381241C096D00F024EE /* SingleContactViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC9A380241C096D00F024EE /* SingleContactViewController.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -24,6 +25,7 @@ ...@@ -24,6 +25,7 @@
CE3351F4241A65D500BA57CA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; CE3351F4241A65D500BA57CA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
CE3351F7241A65D500BA57CA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; CE3351F7241A65D500BA57CA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
CE3351F9241A65D500BA57CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; CE3351F9241A65D500BA57CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CEC259D7241FAC79005237F5 /* File.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = "<group>"; };
CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactsViewController.swift; sourceTree = "<group>"; }; CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactsViewController.swift; sourceTree = "<group>"; };
CEC9A380241C096D00F024EE /* SingleContactViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleContactViewController.swift; sourceTree = "<group>"; }; CEC9A380241C096D00F024EE /* SingleContactViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleContactViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
...@@ -66,6 +68,7 @@ ...@@ -66,6 +68,7 @@
CE3351F9241A65D500BA57CA /* Info.plist */, CE3351F9241A65D500BA57CA /* Info.plist */,
CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */, CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */,
CEC9A380241C096D00F024EE /* SingleContactViewController.swift */, CEC9A380241C096D00F024EE /* SingleContactViewController.swift */,
CEC259D7241FAC79005237F5 /* File.swift */,
); );
path = ContactsApp; path = ContactsApp;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -141,6 +144,7 @@ ...@@ -141,6 +144,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
CEC259D8241FAC79005237F5 /* File.swift in Sources */,
CE3351EC241A65D400BA57CA /* AppDelegate.swift in Sources */, CE3351EC241A65D400BA57CA /* AppDelegate.swift in Sources */,
CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */, CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */,
CE3351EE241A65D400BA57CA /* SceneDelegate.swift in Sources */, CE3351EE241A65D400BA57CA /* SceneDelegate.swift in Sources */,
......
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "FAEBA8FF-01C0-4AC4-9E9A-FC8BDE9B6CFE"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "DD77F967-46EF-4823-80DE-1DB5A3A787F1"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ContactsApp/SingleContactViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26"
endingLineNumber = "26"
landmarkName = "viewDidLoad()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "ECE5C42C-6FA2-494C-BD01-61ED62BE071C"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ContactsApp/SingleContactViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "24"
endingLineNumber = "24"
landmarkName = "viewDidLoad()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
...@@ -14,6 +14,7 @@ class ContactsViewController: UIViewController { ...@@ -14,6 +14,7 @@ class ContactsViewController: UIViewController {
@IBOutlet weak var contactsTable: UITableView! @IBOutlet weak var contactsTable: UITableView!
var contacts = [CNContact]() var contacts = [CNContact]()
var contactsBackup = [CNContact]()
let contactStore = CNContactStore() let contactStore = CNContactStore()
override func viewDidLoad() { override func viewDidLoad() {
...@@ -24,9 +25,8 @@ class ContactsViewController: UIViewController { ...@@ -24,9 +25,8 @@ class ContactsViewController: UIViewController {
func importContacts() { func importContacts() {
let keys = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName)] let keys = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName), CNContactEmailAddressesKey, CNContactPhoneNumbersKey, CNContactImageDataKey, CNContactImageDataAvailableKey] as [Any]
//obtengo let request = CNContactFetchRequest( keysToFetch: keys as! [CNKeyDescriptor])
let request = CNContactFetchRequest(keysToFetch: keys)
request.sortOrder = CNContactSortOrder.givenName request.sortOrder = CNContactSortOrder.givenName
do { do {
try self.contactStore.enumerateContacts(with: request) { try self.contactStore.enumerateContacts(with: request) {
...@@ -66,5 +66,31 @@ extension ContactsViewController: UITableViewDelegate, UITableViewDataSource { ...@@ -66,5 +66,31 @@ extension ContactsViewController: UITableViewDelegate, UITableViewDataSource {
performSegue(withIdentifier: "gotocontact", sender: selectedContact) 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()
}
} }
//
// File.swift
// ContactsApp
//
// Created by User on 3/16/20.
// Copyright © 2020 jheisecke. All rights reserved.
//
import Foundation
class Contacts {
}
...@@ -21,7 +21,7 @@ class SingleContactViewController: UIViewController { ...@@ -21,7 +21,7 @@ class SingleContactViewController: UIViewController {
if let contact = selectedContact{ if let contact = selectedContact{
title = "\(contact.givenName) \(contact.familyName)" title = "\(contact.givenName) \(contact.familyName)"
contactFullname.text = "\(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 contact.imageDataAvailable {
if let image = contact.imageData { if let image = contact.imageData {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment