Posts

Showing posts from October 9, 2018

Swift Async print order?

Image
Clash Royale CLAN TAG #URR8PPP up vote 7 down vote favorite 7 Does this always print in the order of 1 5 2 4 3? print("1") DispatchQueue.main.async print("2") DispatchQueue.main.async print(3) print("4") print("5") I feel the answer is no, but I cannot explain it and hope someone could clarify my understanding. Thank you! swift asynchronous grand-central-dispatch dispatch-async share | improve this question edited 1 hour ago asked 1 hour ago Unikorn 430 1 8 17 1 Yes, it is obvious for 1 ,5 after that it switches to main queue prints 2, Then you again request main queue task but it will not wait for it and prints 4 and then 3 – Prashant Tukadiya 1 hour ago 3 You need to clarify one thing, whether print("1") is executed in the main thread or not. – OOPer 1 hour ago 1 why would it matter? It would always execute first. – Unikorn