{"id":11954,"date":"2015-08-15T20:21:06","date_gmt":"2015-08-16T00:21:06","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=11954"},"modified":"2015-08-15T20:21:06","modified_gmt":"2015-08-16T00:21:06","slug":"dispatch-async-to-main-queue-and-modal-windows","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/08\/15\/dispatch-async-to-main-queue-and-modal-windows\/","title":{"rendered":"Dispatch Async to Main Queue and Modal Windows"},"content":{"rendered":"<p><a href=\"http:\/\/www.thecave.com\/2015\/08\/10\/dispatch-async-to-main-queue-doesnt-work-with-modal-window-on-mac-os-x\/\">Kirby Turner<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.thecave.com\/2015\/08\/10\/dispatch-async-to-main-queue-doesnt-work-with-modal-window-on-mac-os-x\/\">\n<p>Instead of dispatching the <code>completion()<\/code> to the main queue, I call it directly from the background thread. In the completion block itself, I decide how to get the code should run in the main thread. If my window isn&rsquo;t modal, then I can use <code>dispatch_async(dispatch_get_main_queue(), ^{})<\/code>. But if my window is modal, which just happens to be the case for the app I&rsquo;m working on, then I use <code>-performSelectorOnMainThread:withObject:waitUntilDone:<\/code>.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Kirby Turner: Instead of dispatching the completion() to the main queue, I call it directly from the background thread. In the completion block itself, I decide how to get the code should run in the main thread. If my window isn&rsquo;t modal, then I can use dispatch_async(dispatch_get_main_queue(), ^{}). But if my window is modal, which [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,800,880,30,903,54,71],"class_list":["post-11954","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-concurrency","tag-grand-central-dispatch-gcd","tag-mac","tag-mac-os-x-10-10-yosemite","tag-objective-c","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=11954"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11954\/revisions"}],"predecessor-version":[{"id":11955,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11954\/revisions\/11955"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=11954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=11954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=11954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}