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
5c06c519
Commit
5c06c519
authored
Apr 08, 2020
by
Javier Heisekce
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
al borrar el buscador sigue funcionando
parent
3f6e618b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
+13
-6
ContactsApp/ContactsViewController.swift
+13
-6
No files found.
ContactsApp/ContactsViewController.swift
View file @
5c06c519
...
...
@@ -14,6 +14,7 @@ class ContactsViewController: UIViewController {
@IBOutlet
weak
var
searchBar
:
UISearchBar
!
@IBOutlet
weak
var
contactsTable
:
UITableView
!
var
contactStructArray
=
[
ContactStruct
]()
var
contactAux
=
[
ContactStruct
]()
var
contactStruct
:
ContactStruct
?
let
contactStore
=
CNContactStore
()
...
...
@@ -27,6 +28,7 @@ class ContactsViewController: UIViewController {
}
func
importContacts
()
{
self
.
contactStructArray
=
[]
let
keys
=
[
CNContactFormatter
.
descriptorForRequiredKeys
(
for
:
.
fullName
),
CNContactEmailAddressesKey
,
CNContactPhoneNumbersKey
,
CNContactImageDataKey
]
as
[
Any
]
let
request
=
CNContactFetchRequest
(
keysToFetch
:
keys
as!
[
CNKeyDescriptor
])
request
.
sortOrder
=
CNContactSortOrder
.
givenName
...
...
@@ -50,10 +52,10 @@ class ContactsViewController: UIViewController {
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
}
}
}
self
.
contactStructArray
.
append
(
ContactStruct
(
isExpanded
:
true
,
contacts
:
contacts
,
letter
:
auxLetter
))
//agregamos el ultimo nombre
self
.
contactAux
=
self
.
contactStructArray
}
catch
{
print
(
"unable to fetch contacts"
)
...
...
@@ -152,21 +154,26 @@ extension ContactsViewController: UISearchBarDelegate, UISearchDisplayDelegate,
}
func
searchBarCancelButtonClicked
(
_
searchBar
:
UISearchBar
)
{
importContacts
()
contactStructArray
=
contactAux
}
func
searchBar
(
_
searchBar
:
UISearchBar
,
textDidChange
searchText
:
String
)
{
var
foundContacts
=
[
ContactStruct
]()
if
searchText
==
""
{
importContacts
()
contactStructArray
=
contactAux
contactsTable
.
reloadData
()
}
else
{
for
indexContact
in
contactStructArray
.
indices
{
let
contactFound
=
contactStructArray
[
indexContact
]
.
contacts
.
filter
({
$0
.
givenName
.
lowercased
()
.
contains
(
searchText
.
lowercased
())})
for
indexContact
in
contactAux
.
indices
{
let
contactFound
=
contactAux
[
indexContact
]
.
contacts
.
filter
(
{
let
fullName
=
"
\(
$0
.
givenName
)
\(
$0
.
familyName
)
"
return
fullName
.
lowercased
()
.
contains
(
searchText
.
lowercased
())
}
)
if
!
contactFound
.
isEmpty
{
foundContacts
.
append
(
ContactStruct
(
isExpanded
:
true
,
contacts
:
contactFound
,
letter
:
contact
StructArray
[
indexContact
]
.
letter
))
foundContacts
.
append
(
ContactStruct
(
isExpanded
:
true
,
contacts
:
contactFound
,
letter
:
contact
Aux
[
indexContact
]
.
letter
))
}
}
contactStructArray
=
foundContacts
...
...
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