*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'threading violation: expected the main thread'
bug提示如上,定位代码的方式
Edit scheme ——> Run ——> Diagnostics
勾选:Main Thread Checker
运行!
if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {
// main
} else {
dispatch_async(dispatch_get_main_queue(), ^{
});
}
网友评论