Browse Source

Updated progress code samples to show how to call onto the main queue.

Christian Noon 10 years ago
parent
commit
07345a00e5
1 changed files with 12 additions and 0 deletions
  1. 12 0
      README.md

+ 12 - 0
README.md

@@ -322,6 +322,12 @@ Alamofire.upload(.POST, "http://httpbin.org/post", file: fileURL)
 Alamofire.upload(.POST, "http://httpbin.org/post", file: fileURL)
          .progress { bytesWritten, totalBytesWritten, totalBytesExpectedToWrite in
              print(totalBytesWritten)
+
+             // This closure is NOT called on the main queue for performance
+             // reasons. To update your ui, dispatch to the main queue.
+             dispatch_async(dispatch_get_main_queue) {
+                 print("Total bytes written on main queue: \(totalBytesWritten)")
+             }
          }
          .responseJSON { request, response, result in
              debugPrint(result)
@@ -385,6 +391,12 @@ Alamofire.download(.GET, "http://httpbin.org/stream/100", destination: destinati
 Alamofire.download(.GET, "http://httpbin.org/stream/100", destination: destination)
          .progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
              print(totalBytesRead)
+
+             // This closure is NOT called on the main queue for performance
+             // reasons. To update your ui, dispatch to the main queue.
+             dispatch_async(dispatch_get_main_queue) {
+                 print("Total bytes read on main queue: \(totalBytesRead)")
+             }
          }
          .response { request, response, _, error in
              print(response)