title: Swift 3 tableview.reloadData on main thread, not displaying cells properly
body: <p>In a simple TableViewController i am calling ClouKit deleteRecord in a UIAlertController.</p>
  
  <pre><code>    // 2. When the user clicks OK.
      alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { [weak alert] (_) in
          LSCloudKit.shared.deleteRecord(record: login.toCKRecord(), completion: { (success) in
              let index = self.logins.index(of: login);
              self.logins.remove(at: index!);
              self.tableView.reloadData(); // &lt;-problem is here. Data not displayed properly
          });
      }));
  </code></pre>
  
  <p>When i call self.tableView.reloadData(), the table seems to update but it display the wrong list, ie: twice the same cell, sometimes its the one that got deleted and sometimes its another one.</p>
  
  <p>I checked that the call is being made on the main thread. 
  Here is the deleteRecord function too:</p>
  
  <pre><code>func deleteRecord(record: CKRecord!, completion: @escaping (Bool) -&gt; ()) {
      let container = CKContainer.default();
      let privateDatabase = container.privateCloudDatabase;
  
      privateDatabase.delete(withRecordID: record.recordID) { (recordID, error) in
          DispatchQueue.main.async {
              completion(error == nil)
          }
      }
  }
  </code></pre>
  
  <p>If i put a breakpoint in xCode anywhere either inside DispatchQueue.main.async or inside the completion block of "deleteRecord", then everything appears fine on the device once i hit "continue".</p>
  
  <p>The problem happens on simulator and real devices as well. </p>
  
  <p>Please help.</p>
  
  <p>Thank you.</p>
  
  <p><strong>EDIT:</strong> Adding screenshot</p>
  
  <p>Here is the screenshot before and after deleting "user1" from the list, with the output:</p>
  
  <p>self.logins before delete: [admin, master, user1, user2, user3]</p>
  
  <p>self.logins after delete: [admin, master, user2, user3] </p>
  
  <p><a href="https://i.stack.imgur.com/V6LhE.png" rel="nofollow noreferrer">Before delete</a></p>
  
  <p><a href="https://i.stack.imgur.com/KSIpv.png" rel="nofollow noreferrer">After delete</a></p>