Archive for the 'Thread Programming' Category

iOS: Running Code on the Main Thread

Problem: In iOS, updating the user interface should be done in the main thread. However, many asynchronous methods invoke the callback on an arbitrary thread. How can I make sure a particular piece of code is run in the main thread? Solution: You need to use the grand central dispatch: dispatch_async(dispatch_get_main_queue(),^{ // The code to […]