Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var results = [String:Int]()
- func requestData(for identifiers: [String])
- {
- identifiers.forEach
- { identifier in
- service.request(identifier, completion: { (result) in
- result[identifier] = result
- })
- }
- // Execute after all the completion handlers finish
- print(result)
- }
- var results = [String:Int]()
- func requestData(for identifiers: [String])
- {
- let queue = DispatchQueue.init(label: "queue")
- identifiers.forEach
- { identifier in
- service.request(identifier, completion: { (result) in
- queue.sync
- {
- result[identifier] = result
- }
- })
- }
- // Execute after all the completion handlers finish
- queue.sync
- {
- print(result)
- }
- }
Add Comment
Please, Sign In to add comment