Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
contact-list-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
Luis Zarza
contact-list-app
Commits
75f30cac
Commit
75f30cac
authored
Mar 16, 2020
by
Luis Zarza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
search-bar feature added
parent
2ec83e34
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
14 deletions
+54
-14
contact-list-app/Base.lproj/Main.storyboard
+6
-5
contact-list-app/ViewController.swift
+48
-9
No files found.
contact-list-app/Base.lproj/Main.storyboard
View file @
75f30cac
...
...
@@ -50,10 +50,11 @@
</tableViewCell>
</prototypes>
</tableView>
<imageView
clipsSubviews=
"YES"
userInteractionEnabled=
"NO"
contentMode=
"scaleAspectFit"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
fixedFrame=
"YES"
image=
"roshka"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"uXr-7H-u4l"
>
<rect
key=
"frame"
x=
"157"
y=
"96"
width=
"100"
height=
"90"
/>
<autoresizingMask
key=
"autoresizingMask"
flexibleMaxX=
"YES"
flexibleMaxY=
"YES"
/>
</imageView>
<searchBar
contentMode=
"redraw"
fixedFrame=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"6X6-0e-OoT"
>
<rect
key=
"frame"
x=
"0.0"
y=
"113"
width=
"414"
height=
"44"
/>
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
flexibleMaxY=
"YES"
/>
<textInputTraits
key=
"textInputTraits"
/>
</searchBar>
</subviews>
<color
key=
"backgroundColor"
red=
"0.92132973669999996"
green=
"0.93007987739999998"
blue=
"0.952917397"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"sRGB"
/>
<constraints>
...
...
@@ -66,6 +67,7 @@
<navigationItem
key=
"navigationItem"
title=
"Contacts"
id=
"bfK-iM-1Sh"
/>
<connections>
<outlet
property=
"contacsTable"
destination=
"yEq-E4-J6w"
id=
"zMq-Ro-NJS"
/>
<outlet
property=
"searchBar"
destination=
"6X6-0e-OoT"
id=
"v0q-Sp-8An"
/>
</connections>
</viewController>
<placeholder
placeholderIdentifier=
"IBFirstResponder"
id=
"dkx-z0-nzr"
sceneMemberID=
"firstResponder"
/>
...
...
@@ -205,6 +207,5 @@
<image
name=
"envelope"
catalog=
"system"
width=
"64"
height=
"46"
/>
<image
name=
"person.circle.fill"
catalog=
"system"
width=
"64"
height=
"60"
/>
<image
name=
"phone.fill"
catalog=
"system"
width=
"64"
height=
"56"
/>
<image
name=
"roshka"
width=
"400"
height=
"400"
/>
</resources>
</document>
contact-list-app/ViewController.swift
View file @
75f30cac
...
...
@@ -20,11 +20,11 @@ class ViewController: UIViewController {
let
contactStore
=
CNContactStore
()
var
contacts
=
[
CNContact
]()
var
dataSource
:[
ContactList
]?
=
[]
var
backUpContacts
:[
CNContact
]
=
[]
var
contactsArray
:
[
ContactList
]?
=
[]
var
isHidden
=
false
@IBOutlet
weak
var
searchBar
:
UISearchBar
!
@IBOutlet
weak
var
contacsTable
:
UITableView
!
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
//call the main functions
...
...
@@ -41,6 +41,7 @@ class ViewController: UIViewController {
//set tableView handlers to this instance
contacsTable
.
dataSource
=
self
contacsTable
.
delegate
=
self
searchBar
.
delegate
=
self
}
func
sortContacts
(){
...
...
@@ -52,19 +53,20 @@ class ViewController: UIViewController {
temp
.
append
(
contacts
[
i
])
}
else
{
temp
.
append
(
contacts
[
i
])
dataSource
!.
append
(
ContactList
(
firstLetter
:
String
(
pivot
),
contactList
:
temp
))
contactsArray
!.
append
(
ContactList
(
firstLetter
:
String
(
pivot
),
contactList
:
temp
))
pivot
=
contacts
[
i
+
1
]
.
givenName
.
prefix
(
1
)
temp
=
[]
}
}
//ask for the last contact
if
contacts
[
contacts
.
count
-
1
]
.
givenName
.
prefix
(
1
)
==
dataSource
!
[
dataSource
!.
count
-
1
]
.
firstLetter
{
//last group
dataSource
!
[
dataSource
!.
count
-
1
]
.
contactList
.
append
(
contacts
[
contacts
.
count
-
1
])
if
contacts
[
contacts
.
count
-
1
]
.
givenName
.
prefix
(
1
)
==
contactsArray
!
[
contactsArray
!.
count
-
1
]
.
firstLetter
{
//last group
contactsArray
!
[
contactsArray
!.
count
-
1
]
.
contactList
.
append
(
contacts
[
contacts
.
count
-
1
])
}
else
{
//new group
dataSource
!.
append
(
ContactList
(
firstLetter
:
String
(
pivot
),
contactList
:
[
contacts
[
contacts
.
count
-
1
]]))
contactsArray
!.
append
(
ContactList
(
firstLetter
:
String
(
pivot
),
contactList
:
[
contacts
[
contacts
.
count
-
1
]]))
}
dataSource
!
=
contactsArray
!
}
...
...
@@ -173,8 +175,45 @@ extension ViewController: UITableViewDelegate, UITableViewDataSource{
func
tableView
(
_
tableView
:
UITableView
,
didSelectRowAt
indexPath
:
IndexPath
)
{
let
contacProfileVC
=
self
.
storyboard
?
.
instantiateViewController
(
withIdentifier
:
"contactProfileID"
)
as!
ContactProfileVC
let
contacProfileVC
=
self
.
storyboard
?
.
instantiateViewController
(
withIdentifier
:
"contactProfileID"
)
as!
ContactProfileVC
contacProfileVC
.
contact
=
dataSource
!
[
indexPath
.
section
]
.
contactList
[
indexPath
.
row
]
show
(
contacProfileVC
,
sender
:
nil
)
show
(
contacProfileVC
,
sender
:
nil
)
}
}
extension
ViewController
:
UISearchBarDelegate
{
func
searchBar
(
_
searchBar
:
UISearchBar
,
textDidChange
searchText
:
String
)
{
dataSource
!
=
contactsArray
!
if
searchText
.
isEmpty
==
false
{
dataSource
!
=
filterContacts
(
searchText
:
searchText
)
contacsTable
.
reloadData
()
}
else
{
contacsTable
.
reloadData
()
}
}
func
filterContacts
(
searchText
:
String
)
->
[
ContactList
]{
var
filteredContacts
:[
ContactList
]
=
[]
var
contactsTemp
:[
CNContact
]
=
[]
contactsArray
!.
forEach
{
contact
in
contact
.
contactList
.
forEach
{
contacto
in
var
fullName
=
contacto
.
givenName
+
contacto
.
familyName
if
fullName
.
uppercased
()
.
contains
(
searchText
.
uppercased
())
{
contactsTemp
.
append
(
contacto
)
}
}
//en caso de que la seccion tenga coincidencias
if
contactsTemp
.
count
>
0
{
var
contactListAux
=
ContactList
(
firstLetter
:
String
(
contactsTemp
[
0
]
.
givenName
.
prefix
(
1
)),
contactList
:
contactsTemp
)
filteredContacts
.
append
(
contactListAux
)
//se agrega a la lista filtrada
contactsTemp
=
[]
}
}
return
filteredContacts
}
}
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