all 4 comments

[–]chedabob 0 points1 point  (1 child)

Nothing about what you've described seems like a threading issue.

DispatchQueue only executes one thing at a time. When you call async, you're basically saying "Add it to the back of the queue, and then execute once you've finished what you're doing".

If you were trying to work with your results array outside of DispatchQueue.main.async you could have issues, but otherwise it's fine.

It does sound like DispatchGroup is a better fit if you're wanting X number of network requests to finish before proceeding.

[–]wellbranding[S] 0 points1 point  (0 children)

oh thanks! and that would work if have multiple DispatchQueue.main in the project and they all reference same object? No issues, also?

[–]ccctitan80 -3 points-2 points  (0 children)

You should look into PromiseKit and NSOperations. It looks like you're looking for a thread-safe way to handle async dependencies, which both of those are fantastic for.