title: How to use predicates with fetchRequest in Core Data
body: <p>I pass a contact Identifier from Contacts tableview controller to another Location tableview controller. So I  define a delegate ContactSelectionDelegate and implement method userSelectedContact in Location tableview controller and get contactIdentifierString</p>
  
  <p>I am searching the database to find a match for contactIdentifierString and find value for another attribute provider name. This involves searching the whole database. Is there a faster way by assigning a predicate to the context fetchRequest. I thought that would be faster and fewer lines of code.</p>
  
  <p>Can someone suggest how to use predicates with contact fetchRequest?</p>
  
  <p>ContactTableViewController code:</p>
  
  <pre><code>protocol ContactSelectionDelegate{
  func userSelectedContact(contactIdentifier:NSString)
  }
  
  class ContactTableViewController: UITableViewController {
  
  var delegate:ContactSelectionDelegate? = nil
  
  override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  
      if (delegate != nil){
          let contactDict:NSDictionary = allContacts.object(at: indexPath.row) as! NSDictionary
          let identifier = contactDict.object(forKey: "uniqueId")
                     delegate!.userSelectedContact(contactIdentifier: identifier as! NSString)
                    self.navigationController!.popViewController(animated: true)
                 }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>LocationTableViewController code:</p>
  
  <pre><code> class LocationTableViewController: UITableViewController, ContactSelectionDelegate, CLLocationManagerDelegate {
  
  var contactIdentifierString:NSString = NSString()
  
   func userSelectedContact(contactIdentifier: NSString) {
      var fetchedResults: [Contact] = []
  
      let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
  
      do {
          fetchedResults = try context.fetch(Contact.fetchRequest())
      }
      catch {
          print ("fetch task failed")
      }
      if fetchedResults.count &gt; 0 {
          for contact in fetchedResults{
              let aContact:Contact = contact
              if (aContact.uniqueId! == contactIdentifierString as String) {
                  providerName.text = aContact.providerName
              }
              else {
                  continue
              }
          }
      }
  
  
  }
  </code></pre>