许多帖子都说UIKit完全不是线程安全的。现在在GCD的Apple文档中,我们可以看到它的绘图不是线程安全的。所以会像这样的代码即可:UIKit和GCD线程安全
dispatch_async(^ {
//do some work if(!self.window.rootViewController.presentedViewController &&) [self.window.rootViewController class] == anotherClass) { dispatch_async(dispatch_get_main_queue(), ^{ //do some work }); }
});
那么,考虑到rootViewController被声明为'@property(nonatomic,retain)UIViewController * rootViewController',我想不会。 – Mar0ux 2013-04-30 12:27:35
为什么不直接在主线程上进行调度测试。在主线以外的其他线程上使用UI元素时会出现火灾,即使它在iOS 6中正常工作,您的应用可能会在iOS 7中发生严重失败。 – 2013-04-30 12:41:20
导致该块位于另一个dispatch_async()中的while循环中,否则该循环将阻止主线程。 – foFox 2013-04-30 12:44:23