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
3f6e618b
Commit
3f6e618b
authored
5 years ago
by
Javier Heisekce
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Agrega funcionalidad de busqueda de contactos
parent
6ae7dfa8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
+20
-2
ContactsApp/ContactsViewController.swift
+20
-2
No files found.
ContactsApp/ContactsViewController.swift
View file @
3f6e618b
...
@@ -27,7 +27,6 @@ class ContactsViewController: UIViewController {
...
@@ -27,7 +27,6 @@ class ContactsViewController: UIViewController {
}
}
func
importContacts
()
{
func
importContacts
()
{
let
keys
=
[
CNContactFormatter
.
descriptorForRequiredKeys
(
for
:
.
fullName
),
CNContactEmailAddressesKey
,
CNContactPhoneNumbersKey
,
CNContactImageDataKey
]
as
[
Any
]
let
keys
=
[
CNContactFormatter
.
descriptorForRequiredKeys
(
for
:
.
fullName
),
CNContactEmailAddressesKey
,
CNContactPhoneNumbersKey
,
CNContactImageDataKey
]
as
[
Any
]
let
request
=
CNContactFetchRequest
(
keysToFetch
:
keys
as!
[
CNKeyDescriptor
])
let
request
=
CNContactFetchRequest
(
keysToFetch
:
keys
as!
[
CNKeyDescriptor
])
request
.
sortOrder
=
CNContactSortOrder
.
givenName
request
.
sortOrder
=
CNContactSortOrder
.
givenName
...
@@ -152,7 +151,26 @@ extension ContactsViewController: UISearchBarDelegate, UISearchDisplayDelegate,
...
@@ -152,7 +151,26 @@ extension ContactsViewController: UISearchBarDelegate, UISearchDisplayDelegate,
}
}
func
searchBarCancelButtonClicked
(
_
searchBar
:
UISearchBar
)
{
importContacts
()
}
func
searchBar
(
_
searchBar
:
UISearchBar
,
textDidChange
searchText
:
String
)
{
func
searchBar
(
_
searchBar
:
UISearchBar
,
textDidChange
searchText
:
String
)
{
print
(
searchText
)
var
foundContacts
=
[
ContactStruct
]()
if
searchText
==
""
{
importContacts
()
contactsTable
.
reloadData
()
}
else
{
for
indexContact
in
contactStructArray
.
indices
{
let
contactFound
=
contactStructArray
[
indexContact
]
.
contacts
.
filter
({
$0
.
givenName
.
lowercased
()
.
contains
(
searchText
.
lowercased
())})
if
!
contactFound
.
isEmpty
{
foundContacts
.
append
(
ContactStruct
(
isExpanded
:
true
,
contacts
:
contactFound
,
letter
:
contactStructArray
[
indexContact
]
.
letter
))
}
}
contactStructArray
=
foundContacts
contactsTable
.
reloadData
()
}
}
}
}
}
This diff is collapsed.
Click to expand it.
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