title: Swift 4.2 Search contacts with Search Bar using Contacts Framework
body: <p>I'm currently working on a Contact app just to test some features and I'm stuck with the search bar. I can't search between all my contacts in the homepage. Swift 4.2 and Xcode 10</p>
  
  <pre><code>class ContactsViewController: UITableViewController, CNContactViewControllerDelegate, UISearchBarDelegate {
  // Outlet for Search Bar
  @IBOutlet weak var searchBar: UISearchBar!
  </code></pre>
  
  <p>this is the definition of my Delegate on IBOutlet</p>
  
  <p>then my func to show contacts in the homepage</p>
  
  <pre><code>/ * Show Contacts *
  override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      if contactList != nil {
          return contactList.count
      }
      return 0
  }
  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: "contactCell", for: indexPath)
  
      let contact: CNContact!
      contact = contactList[indexPath.row]
  
      cell.textLabel?.text = "\(contact.givenName) \(contact.familyName)"
      return cell
  }
  override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      let contact = contactList[indexPath.row]
      let controller = CNContactViewController(for: contact)
      navigationController?.pushViewController(controller, animated: true)
  }
  </code></pre>
  
  <p>How can I do this searchBar look through my contacts using as key Name or Surname.</p>
  
  <p>Here is one of my attempt but I get an error with <code>contains</code>:</p>
  
  <pre><code>func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
      if searchBar.text == nil || searchBar.text == "" {
          inSearchMode = false
  
          view.endEditing(true)
  
          tableView.reloadData()
      } else {
          inSearchMode = true
  
          filteredData = contactList.filter({$0.contains(searchBar.text!)})
  
          tableView.reloadData()
      }
  }
  </code></pre>