dispatch_async has lag somewhere, can't find where. is there an NSLog problem?

前端 未结 3 2041
眼角桃花
眼角桃花 2021-02-10 09:59

So i have this code:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{

//Bunch of code

NSLog(@\"Test\");

});

w

3条回答
  •  时光说笑
    2021-02-10 10:36

    UIKit isn’t thread-safe. Any calls you make that affect your UI need to be made on the main thread, or you’ll get weird, unpredictable behavior. Example:

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    
        // Background code that doesn't need to update the UI here
    
        dispatch_async(dispatch_get_main_queue(), ^{
            // UI code here
        });
    });
    

提交回复
热议问题