The scenario: the user is presented with a UIAlertController that has a button, with a handler block that updates the UI to indicate the button press. The code in the handler block is wrapped in a dispatch_async to ensure that the code runs on the main thread.
The issue: A code reviewer said the dispatch_async is unnecessary, but neither of us can find a citation to back that up. The Apple documentation about the handler only says
handler A block to execute when the user selects the action. This block has no return value and takes the selected action object as its only parameter.
I can not find anything that guarantees his position -- that a UIAlertAction handler block will always run on the main thread -- is right and in the absence of such, I am inclined to keep the dispatch_async. Is there a definitive statement either way?
@IBAction
you do not need to dispatch here either. The reviewer is correct. – Paulw11dispatch_async
. If the main thread checker doesn't catch a thread error, then you are fine. – aheze