Is it possible to set the NetworkActivityIndicatorVisible value in the secondary stream?

I wonder if AppDelegate is thread safe? I currently have work doing network tasks on the secondary thread, when the task starts, I would like to set NetworkActivityIndicatorVisible to YES , and when the task is completed, set it to NO . Should I always call it in the main thread, or can I do this in the current thread of the loop?

thanks

+4
source share
1 answer

In general, UIKit is not thread safe. Although you can “get away” with some things, you should always do UIKit things in the main thread. There are several well-documented exceptions.

The template for this from the background thread is simple.

 dispatch_async(dispatch_get_main_queue(), ^{ // Put any code you want to execute in the main thread here. }); 

The code inside the block that you pass dispatch_async will be scheduled to run in the main run loop.

+7
source

All Articles