Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
contactos-app
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Javier Heisecke
contactos-app
Commits
6bf83153
Commit
6bf83153
authored
Mar 24, 2020
by
Javier Heisekce
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Agrega ordenamiento de contactos por nombre y divide en secciones
parent
aae30271
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
18 deletions
+48
-18
ContactsApp.xcodeproj/project.pbxproj
+8
-0
ContactsApp/ContactStruct.swift
+1
-0
ContactsApp/ContactsViewController.swift
+39
-18
No files found.
ContactsApp.xcodeproj/project.pbxproj
View file @
6bf83153
...
@@ -15,6 +15,8 @@
...
@@ -15,6 +15,8 @@
CEC259D8241FAC79005237F5
/* ContactStruct.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CEC259D7241FAC79005237F5
/* ContactStruct.swift */
;
};
CEC259D8241FAC79005237F5
/* ContactStruct.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CEC259D7241FAC79005237F5
/* ContactStruct.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 */
;
};
CED5EABE242A4CF800E22547
/* ContactSection.xib in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CED5EABD242A4CF800E22547
/* ContactSection.xib */
;
};
CED5EAC2242A509800E22547
/* ContactSectionTableViewCell.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
CED5EAC1242A509800E22547
/* ContactSectionTableViewCell.swift */
;
};
/* End PBXBuildFile section */
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
/* Begin PBXFileReference section */
...
@@ -28,6 +30,8 @@
...
@@ -28,6 +30,8 @@
CEC259D7241FAC79005237F5
/* ContactStruct.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ContactStruct.swift
;
sourceTree
=
"<group>"
;
};
CEC259D7241FAC79005237F5
/* ContactStruct.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ContactStruct.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>"
;
};
CED5EABD242A4CF800E22547
/* ContactSection.xib */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file.xib
;
path
=
ContactSection.xib
;
sourceTree
=
"<group>"
;
};
CED5EAC1242A509800E22547
/* ContactSectionTableViewCell.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ContactSectionTableViewCell.swift
;
sourceTree
=
"<group>"
;
};
/* End PBXFileReference section */
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
/* Begin PBXFrameworksBuildPhase section */
...
@@ -69,6 +73,8 @@
...
@@ -69,6 +73,8 @@
CEC9A37E241BFBD000F024EE
/* ContactsViewController.swift */
,
CEC9A37E241BFBD000F024EE
/* ContactsViewController.swift */
,
CEC9A380241C096D00F024EE
/* SingleContactViewController.swift */
,
CEC9A380241C096D00F024EE
/* SingleContactViewController.swift */
,
CEC259D7241FAC79005237F5
/* ContactStruct.swift */
,
CEC259D7241FAC79005237F5
/* ContactStruct.swift */
,
CED5EABD242A4CF800E22547
/* ContactSection.xib */
,
CED5EAC1242A509800E22547
/* ContactSectionTableViewCell.swift */
,
);
);
path
=
ContactsApp
;
path
=
ContactsApp
;
sourceTree
=
"<group>"
;
sourceTree
=
"<group>"
;
...
@@ -131,6 +137,7 @@
...
@@ -131,6 +137,7 @@
isa
=
PBXResourcesBuildPhase
;
isa
=
PBXResourcesBuildPhase
;
buildActionMask
=
2147483647
;
buildActionMask
=
2147483647
;
files
=
(
files
=
(
CED5EABE242A4CF800E22547
/* ContactSection.xib in Resources */
,
CE3351F8241A65D500BA57CA
/* LaunchScreen.storyboard in Resources */
,
CE3351F8241A65D500BA57CA
/* LaunchScreen.storyboard in Resources */
,
CE3351F5241A65D500BA57CA
/* Assets.xcassets in Resources */
,
CE3351F5241A65D500BA57CA
/* Assets.xcassets in Resources */
,
CE3351F3241A65D400BA57CA
/* Main.storyboard in Resources */
,
CE3351F3241A65D400BA57CA
/* Main.storyboard in Resources */
,
...
@@ -144,6 +151,7 @@
...
@@ -144,6 +151,7 @@
isa
=
PBXSourcesBuildPhase
;
isa
=
PBXSourcesBuildPhase
;
buildActionMask
=
2147483647
;
buildActionMask
=
2147483647
;
files
=
(
files
=
(
CED5EAC2242A509800E22547
/* ContactSectionTableViewCell.swift in Sources */
,
CEC259D8241FAC79005237F5
/* ContactStruct.swift in Sources */
,
CEC259D8241FAC79005237F5
/* ContactStruct.swift in Sources */
,
CE3351EC241A65D400BA57CA
/* AppDelegate.swift in Sources */
,
CE3351EC241A65D400BA57CA
/* AppDelegate.swift in Sources */
,
CEC9A37F241BFBD000F024EE
/* ContactsViewController.swift in Sources */
,
CEC9A37F241BFBD000F024EE
/* ContactsViewController.swift in Sources */
,
...
...
ContactsApp/ContactStruct.swift
View file @
6bf83153
...
@@ -12,4 +12,5 @@ import ContactsUI
...
@@ -12,4 +12,5 @@ import ContactsUI
struct
ContactStruct
{
struct
ContactStruct
{
var
isExpanded
:
Bool
var
isExpanded
:
Bool
let
contacts
:
[
CNContact
]
let
contacts
:
[
CNContact
]
let
letter
:
String
}
}
ContactsApp/ContactsViewController.swift
View file @
6bf83153
...
@@ -12,9 +12,8 @@ import ContactsUI
...
@@ -12,9 +12,8 @@ import ContactsUI
class
ContactsViewController
:
UIViewController
{
class
ContactsViewController
:
UIViewController
{
@IBOutlet
weak
var
contactsTable
:
UITableView
!
@IBOutlet
weak
var
contactsTable
:
UITableView
!
var
contactStruct
=
[
ContactStruct
]()
var
contactStructArray
=
[
ContactStruct
]()
var
contacts
=
[
CNContact
]()
var
contactStruct
:
ContactStruct
?
//var contactsBackup = [CNContact]()
let
contactStore
=
CNContactStore
()
let
contactStore
=
CNContactStore
()
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
...
@@ -29,19 +28,36 @@ class ContactsViewController: UIViewController {
...
@@ -29,19 +28,36 @@ class ContactsViewController: UIViewController {
let
request
=
CNContactFetchRequest
(
keysToFetch
:
keys
as!
[
CNKeyDescriptor
])
let
request
=
CNContactFetchRequest
(
keysToFetch
:
keys
as!
[
CNKeyDescriptor
])
request
.
sortOrder
=
CNContactSortOrder
.
givenName
request
.
sortOrder
=
CNContactSortOrder
.
givenName
do
{
do
{
var
auxLetter
=
""
var
contacts
=
[
CNContact
]()
var
isNotTheFirst
=
false
try
self
.
contactStore
.
enumerateContacts
(
with
:
request
)
{
try
self
.
contactStore
.
enumerateContacts
(
with
:
request
)
{
(
contact
,
stop
)
in
(
contact
,
stop
)
in
// Array containing all unified contacts from everywhere
if
contact
.
givenName
.
prefix
(
1
)
==
auxLetter
{
self
.
contacts
.
append
(
contact
)
contacts
.
append
(
contact
)
}
else
{
if
isNotTheFirst
{
let
contactsExpandables
=
ContactStruct
(
isExpanded
:
true
,
contacts
:
contacts
,
letter
:
auxLetter
)
self
.
contactStructArray
.
append
(
contactsExpandables
)
//guardamos el contacto expandible anterior
auxLetter
=
String
(
contact
.
givenName
.
prefix
(
1
))
//guardamos la nueva letra
contacts
=
[
CNContact
]()
//inicializamos nuevamente el array de contactos
contacts
.
append
(
contact
)
//guardamos el nuevo contacto
}
else
{
contacts
.
append
(
contact
)
auxLetter
=
String
(
contact
.
givenName
.
prefix
(
1
))
//auxLetter tiene la primera letra del nombre
isNotTheFirst
=
true
//la siguiente vez que las letras no sean iguales guardara en el array
}
}
}
}
let
contactsExpandables
=
ContactStruct
(
isExpanded
:
true
,
contacts
:
contacts
)
self
.
contactStructArray
.
append
(
ContactStruct
(
isExpanded
:
true
,
contacts
:
contacts
,
letter
:
auxLetter
))
//agregamos el ultimo nombre
self
.
contactStruct
=
[
contactsExpandables
]
print
(
"CONTACTOS ORDENADOS"
)
print
(
self
.
contactStructArray
)
print
(
"======================"
)
}
}
catch
{
catch
{
print
(
"unable to fetch contacts"
)
print
(
"unable to fetch contacts"
)
}
}
print
(
contacts
)
}
}
override
func
prepare
(
for
segue
:
UIStoryboardSegue
,
sender
:
Any
?)
{
override
func
prepare
(
for
segue
:
UIStoryboardSegue
,
sender
:
Any
?)
{
...
@@ -53,17 +69,22 @@ class ContactsViewController: UIViewController {
...
@@ -53,17 +69,22 @@ class ContactsViewController: UIViewController {
}
}
}
}
extension
ContactsViewController
:
UITableViewDelegate
,
UITableViewDataSource
{
extension
ContactsViewController
:
UITableViewDelegate
,
UITableViewDataSource
{
func
numberOfSections
(
in
tableView
:
UITableView
)
->
Int
{
return
contactStructArray
.
count
}
func
tableView
(
_
tableView
:
UITableView
,
numberOfRowsInSection
section
:
Int
)
->
Int
{
func
tableView
(
_
tableView
:
UITableView
,
numberOfRowsInSection
section
:
Int
)
->
Int
{
if
!
contactStruct
[
section
]
.
isExpanded
{
if
!
contactStruct
Array
[
section
]
.
isExpanded
{
return
0
return
0
}
}
return
contactStruct
[
section
]
.
contacts
.
count
return
contactStruct
Array
[
section
]
.
contacts
.
count
}
}
func
tableView
(
_
tableView
:
UITableView
,
cellForRowAt
indexPath
:
IndexPath
)
->
UITableViewCell
{
func
tableView
(
_
tableView
:
UITableView
,
cellForRowAt
indexPath
:
IndexPath
)
->
UITableViewCell
{
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
"contactName"
)
!
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
"contactName"
)
!
let
contactCell
=
contactStruct
[
indexPath
.
section
]
.
contacts
[
indexPath
.
row
]
let
contactCell
=
contactStruct
Array
[
indexPath
.
section
]
.
contacts
[
indexPath
.
row
]
cell
.
textLabel
?
.
text
=
"
\(
contactCell
.
givenName
)
\(
contactCell
.
familyName
)
"
cell
.
textLabel
?
.
text
=
"
\(
contactCell
.
givenName
)
\(
contactCell
.
familyName
)
"
...
@@ -71,7 +92,7 @@ extension ContactsViewController: UITableViewDelegate, UITableViewDataSource {
...
@@ -71,7 +92,7 @@ extension ContactsViewController: UITableViewDelegate, UITableViewDataSource {
}
}
func
tableView
(
_
tableView
:
UITableView
,
didSelectRowAt
indexPath
:
IndexPath
)
{
func
tableView
(
_
tableView
:
UITableView
,
didSelectRowAt
indexPath
:
IndexPath
)
{
let
selectedContact
=
contacts
[
indexPath
.
row
]
let
selectedContact
=
contact
StructArray
[
indexPath
.
section
]
.
contact
s
[
indexPath
.
row
]
performSegue
(
withIdentifier
:
"gotocontact"
,
sender
:
selectedContact
)
performSegue
(
withIdentifier
:
"gotocontact"
,
sender
:
selectedContact
)
}
}
...
@@ -85,23 +106,23 @@ extension ContactsViewController: UITableViewDelegate, UITableViewDataSource {
...
@@ -85,23 +106,23 @@ extension ContactsViewController: UITableViewDelegate, UITableViewDataSource {
button
.
setTitleColor
(
.
black
,
for
:
.
normal
)
button
.
setTitleColor
(
.
black
,
for
:
.
normal
)
button
.
titleLabel
?
.
font
=
UIFont
.
boldSystemFont
(
ofSize
:
15
)
button
.
titleLabel
?
.
font
=
UIFont
.
boldSystemFont
(
ofSize
:
15
)
button
.
backgroundColor
=
.
systemGray4
button
.
backgroundColor
=
.
systemGray4
button
.
addTarget
(
self
,
action
:
#selector(
close
Section
)
,
for
:
.
touchUpInside
)
button
.
addTarget
(
self
,
action
:
#selector(
interact
Section
)
,
for
:
.
touchUpInside
)
button
.
tag
=
section
button
.
tag
=
section
return
button
//ʌΛ
return
button
//ʌΛ
}
}
@objc
func
close
Section
(
button
:
UIButton
)
{
@objc
func
interact
Section
(
button
:
UIButton
)
{
//contactsBackup = contacts
//contactsBackup = contacts
let
section
=
button
.
tag
let
section
=
button
.
tag
var
indexPaths
=
[
IndexPath
]()
var
indexPaths
=
[
IndexPath
]()
for
row
in
contactStruct
[
section
]
.
contacts
.
indices
{
for
row
in
contactStruct
Array
[
section
]
.
contacts
.
indices
{
let
indexPath
=
IndexPath
(
row
:
row
,
section
:
section
)
let
indexPath
=
IndexPath
(
row
:
row
,
section
:
section
)
indexPaths
.
append
(
indexPath
)
indexPaths
.
append
(
indexPath
)
}
}
let
isExpanded
=
contactStruct
[
section
]
.
isExpanded
let
isExpanded
=
contactStruct
Array
[
section
]
.
isExpanded
contactStruct
[
section
]
.
isExpanded
=
!
isExpanded
contactStruct
Array
[
section
]
.
isExpanded
=
!
isExpanded
button
.
setTitle
(
isExpanded
?
"V"
:
"Λ"
,
for
:
.
normal
)
button
.
setTitle
(
isExpanded
?
"V"
:
"Λ"
,
for
:
.
normal
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment