title: Update progress bar while writing files swift 3
body: <p>I'm using swift 3 to write an iOS app. I'm trying to write a bunch of files in a loop and show progress in the UI. The loop goes: </p>
  
  <ol>
  <li>write file</li>
  <li>Check remaining disk space</li>
  <li>Update UI and progress bar</li>
  <li>Loop</li>
  </ol>
  
  <p>The UI is not updating until the loop completely finishes. Funny enough, I update the UI with initial values FIRST THING in the ViewDidAppear function, before the loop even starts and that update doesn't even happen until after the loop finishes. Here is a code sample:</p>
  
  <pre><code>for _ in 0...100000 {
          let image = UIImage(name: "someimage_\(nameExt!).png")
          if let data = UIImagePNGRepresentation(image) {
              let filename = getDocumentsDirectory().appendingPathComponent("myimage_\(nameExt!).png")
              nameExt! = nameExt! + 1
              try? data.write(to: filename)
          }
  
              let currentSpace = getSpace()
              progress?.progress = abs( Float((capacity!-currentSpace)/capacity!) )
              let progressValue = progress?.progress
              progressLabel?.text = "\(progressValue! * 100) %"
              spaceRemaining?.text = "free space: \(currentSpace/1000000) MB"
              print("free space: \(currentSpace/1000000000) GB")
              print("\(progressValue! * 100) %")
              print("----------")
  }
  </code></pre>