Note that there are some explanatory texts on larger screens.

plurals
  1. PODetect UI actions outside of main thread
    text
    copied!<p>Note: This question is related to <a href="https://stackoverflow.com/questions/10976424/warn-on-calls-to-uikit-from-background-threads">Warn on calls to UIKit from background threads</a> but does not give an answer on two of the approaches below.</p> <p>I have a problem where the app screen blinks rapidly. I already had that problem in the past and it is due to updating the UI elements outside the main thread.</p> <p>Therefore I've put the following code in many places:</p> <pre><code>assertMainThread(); </code></pre> <p>which is:</p> <pre><code>#define assertMainThread() NSAssert([NSThread isMainThread],@"Method called using a thread other than main!") </code></pre> <p>Of course I cannot cover the whole code with assertMainThread() as there are many places and some code is used in a legitimate way by background GCD queues.</p> <p>I looked at many places, but could not find a way for XCode or LLDB to tell me when a UI element is updated outside the main thread. I thought that one could use symbolic breakpoints or some other mechanism to break at the place where a common method in UIKit is called outside of main thread for example, but could not find a way.</p> <p>I also thought that UIKit could warn at runtime when such a call is made? Or at least give us some tools to see help debug such problems. </p> <p>Another approach I looked (but did not try) is to use some code coverage techniques and try to extract what thread was running at what point in the code visually, but did not go that route.</p> <p>Do you have any idea on how to tackle the problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload