Guest User

Untitled

a guest
Nov 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. var results = [String:Int]()
  2.  
  3. func requestData(for identifiers: [String])
  4. {
  5. identifiers.forEach
  6. { identifier in
  7.  
  8. service.request(identifier, completion: { (result) in
  9. result[identifier] = result
  10. })
  11. }
  12.  
  13. // Execute after all the completion handlers finish
  14. print(result)
  15. }
  16.  
  17. var results = [String:Int]()
  18.  
  19. func requestData(for identifiers: [String])
  20. {
  21. let queue = DispatchQueue.init(label: "queue")
  22.  
  23. identifiers.forEach
  24. { identifier in
  25.  
  26. service.request(identifier, completion: { (result) in
  27. queue.sync
  28. {
  29. result[identifier] = result
  30. }
  31. })
  32. }
  33.  
  34. // Execute after all the completion handlers finish
  35. queue.sync
  36. {
  37. print(result)
  38. }
  39. }
Add Comment
Please, Sign In to add comment