Explorar el Código

Added an optional bind around the response to safely extract headers.

John Pope hace 10 años
padre
commit
2bffaf1b8e
Se han modificado 1 ficheros con 4 adiciones y 2 borrados
  1. 4 2
      Example/DetailViewController.swift

+ 4 - 2
Example/DetailViewController.swift

@@ -79,8 +79,10 @@ class DetailViewController: UITableViewController {
             let end = CACurrentMediaTime()
             self.elapsedTime = end - start
 
-            for (field, value) in response!.allHeaderFields {
-                self.headers["\(field)"] = "\(value)"
+            if let response = response {
+                for (field, value) in response.allHeaderFields {
+                    self.headers["\(field)"] = "\(value)"
+                }
             }
 
             if let segueIdentifier = self.segueIdentifier {