title: How to update a field on a Record Type in CloudKit?
body: <p>I'm trying to update a existing Record in CloudKit but I'm creating a new Record instead of changing the value! Here it is the code: </p>
  
  <pre><code>func pairing(phone: String, ctid: String) {
      ctUsers = [CKRecord]()
      print("THE PHONE IS: \(phone)\n")
  
      let publicData = CKContainer.default().publicCloudDatabase
      let predicate = Predicate(format: "phone == %@", phone)
      let query = CKQuery(recordType: "Elder", predicate: predicate)
  
      publicData.perform(query, inZoneWith: nil) { (results: [CKRecord]?, error: NSError?) -&gt; Void in
          if error != nil {
              print(error?.localizedDescription)
          }
  
          if let users = results {
              self.ctUsers = users
              print("\nHow many users in cloud: \(self.ctUsers.count)\n")
  
              if self.ctUsers.count != 0 {
  
                  let user = CKRecord(recordType: "Elder")
                  user["careTakerId"] = ctid
  
                  let publicData = CKContainer.default().publicCloudDatabase
                  publicData.save(user, completionHandler: { (record: CKRecord?, error: NSError?) in
                      if error == nil {
  
                          DispatchQueue.main.asynchronously(execute: { () -&gt; Void in
                              print("CARETAKER updated successfully\n")
                          })
                      }
                      else {
                          print("\nHUEHUEHUEHUE\n")
                          print(error?.localizedDescription)
                      }
                  })
              }
              else {
                  print("\nELDER ISN'T IN CLOUD\n")
                  print(error?.localizedDescription)
              }
          }
      }
  }
  </code></pre>
  
  <p>Quick explanation: First I'm getting the elder's phone number (every elder has a different phone) and check if this phone number is in cloud. If it is, then updates the <em>careTakerId</em> of THIS elder, specifically!</p>
  
  <p><a href="https://i.stack.imgur.com/Fd8bA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Fd8bA.png" alt=""></a>
  Here you can see that is creating this "No Name" record and the record above remains unchanged</p>
  
  <p>Any ideas?</p>