Commit 92cc2d0f by Javier Heisekce

Initial commit

parent c7f78d33
......@@ -9,21 +9,23 @@
/* Begin PBXBuildFile section */
CE3351EC241A65D400BA57CA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3351EB241A65D400BA57CA /* AppDelegate.swift */; };
CE3351EE241A65D400BA57CA /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3351ED241A65D400BA57CA /* SceneDelegate.swift */; };
CE3351F0241A65D400BA57CA /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3351EF241A65D400BA57CA /* ViewController.swift */; };
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 */; };
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 */
/* Begin PBXFileReference section */
CE3351E8241A65D400BA57CA /* ContactsApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ContactsApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
CE3351EB241A65D400BA57CA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
CE3351ED241A65D400BA57CA /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
CE3351EF241A65D400BA57CA /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
CE3351F2241A65D400BA57CA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; 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>"; };
CE3351F9241A65D500BA57CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; 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>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -58,11 +60,12 @@
children = (
CE3351EB241A65D400BA57CA /* AppDelegate.swift */,
CE3351ED241A65D400BA57CA /* SceneDelegate.swift */,
CE3351EF241A65D400BA57CA /* ViewController.swift */,
CE3351F1241A65D400BA57CA /* Main.storyboard */,
CE3351F4241A65D500BA57CA /* Assets.xcassets */,
CE3351F6241A65D500BA57CA /* LaunchScreen.storyboard */,
CE3351F9241A65D500BA57CA /* Info.plist */,
CEC9A37E241BFBD000F024EE /* ContactsViewController.swift */,
CEC9A380241C096D00F024EE /* SingleContactViewController.swift */,
);
path = ContactsApp;
sourceTree = "<group>";
......@@ -138,9 +141,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CE3351F0241A65D400BA57CA /* ViewController.swift in Sources */,
CE3351EC241A65D400BA57CA /* AppDelegate.swift in Sources */,
CEC9A37F241BFBD000F024EE /* ContactsViewController.swift in Sources */,
CE3351EE241A65D400BA57CA /* SceneDelegate.swift in Sources */,
CEC9A381241C096D00F024EE /* SingleContactViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
<?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>
//
// ContactsViewController.swift
// ContactsApp
//
// Created by User on 3/13/20.
// Copyright © 2020 jheisecke. All rights reserved.
//
import UIKit
import ContactsUI
class ContactsViewController: UIViewController {
@IBOutlet weak var contactsTable: UITableView!
var contacts = [CNContact]()
let contactStore = CNContactStore()
override func viewDidLoad() {
super.viewDidLoad()
importContacts()
contactsTable.tableFooterView = UIView(frame: .zero)
}
func importContacts() {
let keys = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName)]
//obtengo
let request = CNContactFetchRequest(keysToFetch: keys)
request.sortOrder = CNContactSortOrder.givenName
do {
try self.contactStore.enumerateContacts(with: request) {
(contact, stop) in
// Array containing all unified contacts from everywhere
self.contacts.append(contact)
}
}
catch {
print("unable to fetch contacts")
}
print(contacts)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let singleContactVC = segue.destination as? SingleContactViewController {
if let selectedCnt = sender as? CNContact {
singleContactVC.selectedContact = selectedCnt
}
}
}
}
extension ContactsViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return contacts.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "contactName")!
cell.textLabel?.text = "\(contacts[indexPath.row].givenName) \(contacts[indexPath.row].familyName)"
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let selectedContact = contacts[indexPath.row]
performSegue(withIdentifier: "gotocontact", sender: selectedContact)
}
}
......@@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSContactsUsageDescription</key>
<string>Voy a spamear a tus contactos</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
......
//
// SingleContactViewController.swift
// ContactsApp
//
// Created by User on 3/13/20.
// Copyright © 2020 jheisecke. All rights reserved.
//
import UIKit
import ContactsUI
class SingleContactViewController: UIViewController {
@IBOutlet weak var contactFullname: UILabel!
var selectedContact : CNContact?
@IBOutlet weak var profilePic: UIImageView!
@IBOutlet weak var phoneNumber: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
if let contact = selectedContact{
title = "\(contact.givenName) \(contact.familyName)"
contactFullname.text = "\(contact.givenName) \(contact.familyName)"
phoneNumber.text = contact.phoneNumbers.description
if contact.imageDataAvailable {
if let image = contact.imageData {
if let imageData = UIImage(data: image){
profilePic.image = imageData
}
}
}
}
}
}
//
// ViewController.swift
// ContactsApp
//
// Created by User on 3/12/20.
// Copyright © 2020 jheisecke. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
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