dispatch-async
Does dispatch_async(dispatch_get_main_queue(), ^{…}); wait until done?
No it doesn’t wait and the way you are doing it in that sample is not good practice. dispatch_async is always asynchronous. It’s just that you are enqueueing all the UI blocks to the same queue so the different blocks will run in sequence but parallel with your data processing code. If you want the … Read more
iPhone – Grand Central Dispatch main thread
Dispatching a block to the main queue is usually done from a background queue to signal that some background processing has finished e.g. – (void)doCalculation { //you can use any string instead “com.mycompany.myqueue” dispatch_queue_t backgroundQueue = dispatch_queue_create(“com.mycompany.myqueue”, 0); dispatch_async(backgroundQueue, ^{ int result = <some really long calculation that takes seconds to complete>; dispatch_async(dispatch_get_main_queue(), ^{ [self … Read more
Understanding dispatch_async
The main reason you use the default queue over the main queue is to run tasks in the background. For instance, if I am downloading a file from the internet and I want to update the user on the progress of the download, I will run the download in the priority default queue and update … Read more
How do I dispatch_sync, dispatch_async, dispatch_after, etc in Swift 3, Swift 4, and beyond?
Since the beginning, Swift has provided some facilities for making ObjC and C more Swifty, adding more with each version. Now, in Swift 3, the new “import as member” feature lets frameworks with certain styles of C API — where you have a data type that works sort of like a class, and a bunch … Read more