title: My CloudKit app made with swift4/xcode10 work only in simulator
body: <p>I try to save and retrieve an array from iCloud. Then, i want to print result and display the result in a label. </p>
  
  <p>In simulator, the result is printed instantly but the text in the label is just show after aprox 15 seconds, don't understand why i got this delay!</p>
  
  <p>Anyway, my code work in the simulator (or in a device linked directly to Xcode) but when i send the app to "testflight" and download it from there it no longer display the result in my label.</p>
  
  <p>My testers have try it on different device, with no result: nothing is show in the label after app is sent to test flight</p>
  
  <pre><code> import UIKit
   import CloudKit
  
   class ViewController: UIViewController {
  
      struct Structure: Codable {
          var a, b, c, d : String
          var e : Double
      }
  
  
      var var1 = [
          Structure(a: "-1", b: "111", c: "aaa", d: "2017-01-21 05:55:55", e: 1),
          Structure(a: "111.1", b: "-1", c: "AAAAAA", d: "2018-04-27 07:54:25", e: 11)]
  
      var var2 = [
          Structure(a: "", b: "", c: "", d: "", e: 0),
          Structure(a: "", b: "", c: "", d: "", e: 0)]
  
  
      @IBOutlet weak var Label: UILabel!
  
  
      @IBAction func Save(_ sender: Any) {
          // Delete old record
          let query = CKQuery(recordType: "Structure", predicate: NSPredicate(value: true))
          CKContainer.default().privateCloudDatabase.perform(query, inZoneWith: nil) { (records, error) in
  
              if error == nil {
                  for record in records! {
                      CKContainer.default().privateCloudDatabase.delete(withRecordID: record.recordID, completionHandler: { (recordId, error) in })
                  }
                  print("Deleted record")
              }
          }
  
          // Save var1
          let myRecord = CKRecord(recordType: "Structure")
          if let data = try? JSONEncoder().encode(var1) {
              myRecord["Content1"] = data
          }
          CKContainer.default().privateCloudDatabase.save(myRecord) { (record, error) in
              guard record != nil else { return }
              print("saved var1")
          }
      }
  
  
  
  
      @IBAction func Load(_ sender: Any) {
  
          let query = CKQuery(recordType: "Structure", predicate: NSPredicate(value: true))
  
          CKContainer.default().privateCloudDatabase.perform(query, inZoneWith: nil) { (records, error) in
              records?.forEach({ (record) in
  
                  let content = record.value(forKey: "Content1")
  
                  //convert data to var2
                  if let lp = content as? Data{
                      if let valuefromicloud = try? JSONDecoder().decode(Array.self, from: lp) as [Structure]{
                          self.var2 = valuefromicloud
                      }
                  }
                  //The next line print result instantly
                  print("Data from iCloud: \(self.var2[0].b)")
  
                  //The next line show result after aprox 15 sec delay, why this delay???
                  self.Label.text =  "Data from iCloud: \(self.var2[0].b)"
              })
          }}
   }
  </code></pre>
  
  <p>So, i have three questions:</p>
  
  <p>1: Why does result is printed instantly, but label need aprox 15 sec to be updated in simulator?</p>
  
  <p>2: Why does my app no longer update his label after my testers download it from test flight?</p>
  
  <p>3: Can you give me an exemple of a working code that save/retreive my array from iCloud?</p>