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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
11 deletions
+51
-11
contact-list-app/Base.lproj/Main.storyboard
+6
-5
contact-list-app/ViewController.swift
+45
-6
No files found.
contact-list-app/Base.lproj/Main.storyboard
View file @
75f30cac
...
@@ -50,10 +50,11 @@
...
@@ -50,10 +50,11 @@
</tableViewCell>
</tableViewCell>
</prototypes>
</prototypes>
</tableView>
</tableView>
<imageView
clipsSubviews=
"YES"
userInteractionEnabled=
"NO"
contentMode=
"scaleAspectFit"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
fixedFrame=
"YES"
image=
"roshka"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"uXr-7H-u4l"
>
<searchBar
contentMode=
"redraw"
fixedFrame=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"6X6-0e-OoT"
>
<rect
key=
"frame"
x=
"157"
y=
"96"
width=
"100"
height=
"90"
/>
<rect
key=
"frame"
x=
"0.0"
y=
"113"
width=
"414"
height=
"44"
/>
<autoresizingMask
key=
"autoresizingMask"
flexibleMaxX=
"YES"
flexibleMaxY=
"YES"
/>
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
flexibleMaxY=
"YES"
/>
</imageView>
<textInputTraits
key=
"textInputTraits"
/>
</searchBar>
</subviews>
</subviews>
<color
key=
"backgroundColor"
red=
"0.92132973669999996"
green=
"0.93007987739999998"
blue=
"0.952917397"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"sRGB"
/>
<color
key=
"backgroundColor"
red=
"0.92132973669999996"
green=
"0.93007987739999998"
blue=
"0.952917397"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"sRGB"
/>
<constraints>
<constraints>
...
@@ -66,6 +67,7 @@
...
@@ -66,6 +67,7 @@
<navigationItem
key=
"navigationItem"
title=
"Contacts"
id=
"bfK-iM-1Sh"
/>
<navigationItem
key=
"navigationItem"
title=
"Contacts"
id=
"bfK-iM-1Sh"
/>
<connections>
<connections>
<outlet
property=
"contacsTable"
destination=
"yEq-E4-J6w"
id=
"zMq-Ro-NJS"
/>
<outlet
property=
"contacsTable"
destination=
"yEq-E4-J6w"
id=
"zMq-Ro-NJS"
/>
<outlet
property=
"searchBar"
destination=
"6X6-0e-OoT"
id=
"v0q-Sp-8An"
/>
</connections>
</connections>
</viewController>
</viewController>
<placeholder
placeholderIdentifier=
"IBFirstResponder"
id=
"dkx-z0-nzr"
sceneMemberID=
"firstResponder"
/>
<placeholder
placeholderIdentifier=
"IBFirstResponder"
id=
"dkx-z0-nzr"
sceneMemberID=
"firstResponder"
/>
...
@@ -205,6 +207,5 @@
...
@@ -205,6 +207,5 @@
<image
name=
"envelope"
catalog=
"system"
width=
"64"
height=
"46"
/>
<image
name=
"envelope"
catalog=
"system"
width=
"64"
height=
"46"
/>
<image
name=
"person.circle.fill"
catalog=
"system"
width=
"64"
height=
"60"
/>
<image
name=
"person.circle.fill"
catalog=
"system"
width=
"64"
height=
"60"
/>
<image
name=
"phone.fill"
catalog=
"system"
width=
"64"
height=
"56"
/>
<image
name=
"phone.fill"
catalog=
"system"
width=
"64"
height=
"56"
/>
<image
name=
"roshka"
width=
"400"
height=
"400"
/>
</resources>
</resources>
</document>
</document>
contact-list-app/ViewController.swift
View file @
75f30cac
...
@@ -20,9 +20,9 @@ class ViewController: UIViewController {
...
@@ -20,9 +20,9 @@ class ViewController: UIViewController {
let
contactStore
=
CNContactStore
()
let
contactStore
=
CNContactStore
()
var
contacts
=
[
CNContact
]()
var
contacts
=
[
CNContact
]()
var
dataSource
:[
ContactList
]?
=
[]
var
dataSource
:[
ContactList
]?
=
[]
var
backUpContacts
:[
CNContact
]
=
[]
var
contactsArray
:
[
ContactList
]?
=
[]
var
isHidden
=
false
var
isHidden
=
false
@IBOutlet
weak
var
searchBar
:
UISearchBar
!
@IBOutlet
weak
var
contacsTable
:
UITableView
!
@IBOutlet
weak
var
contacsTable
:
UITableView
!
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
...
@@ -41,6 +41,7 @@ class ViewController: UIViewController {
...
@@ -41,6 +41,7 @@ class ViewController: UIViewController {
//set tableView handlers to this instance
//set tableView handlers to this instance
contacsTable
.
dataSource
=
self
contacsTable
.
dataSource
=
self
contacsTable
.
delegate
=
self
contacsTable
.
delegate
=
self
searchBar
.
delegate
=
self
}
}
func
sortContacts
(){
func
sortContacts
(){
...
@@ -52,19 +53,20 @@ class ViewController: UIViewController {
...
@@ -52,19 +53,20 @@ class ViewController: UIViewController {
temp
.
append
(
contacts
[
i
])
temp
.
append
(
contacts
[
i
])
}
else
{
}
else
{
temp
.
append
(
contacts
[
i
])
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
)
pivot
=
contacts
[
i
+
1
]
.
givenName
.
prefix
(
1
)
temp
=
[]
temp
=
[]
}
}
}
}
//ask for the last contact
//ask for the last contact
if
contacts
[
contacts
.
count
-
1
]
.
givenName
.
prefix
(
1
)
==
dataSource
!
[
dataSource
!.
count
-
1
]
.
firstLetter
{
//last group
if
contacts
[
contacts
.
count
-
1
]
.
givenName
.
prefix
(
1
)
==
contactsArray
!
[
contactsArray
!.
count
-
1
]
.
firstLetter
{
//last group
dataSource
!
[
dataSource
!.
count
-
1
]
.
contactList
.
append
(
contacts
[
contacts
.
count
-
1
])
contactsArray
!
[
contactsArray
!.
count
-
1
]
.
contactList
.
append
(
contacts
[
contacts
.
count
-
1
])
}
else
{
//new group
}
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
!
}
}
...
@@ -178,3 +180,40 @@ extension ViewController: UITableViewDelegate, UITableViewDataSource{
...
@@ -178,3 +180,40 @@ extension ViewController: UITableViewDelegate, UITableViewDataSource{
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