【发布时间】:2013-04-24 08:53:22
【问题描述】:
许多帖子说 UIKit 完全不是线程安全的。现在在 GCD 的 Apple 文档中,我们可以读到 DRAWING 不是线程安全的。那么这样的代码可以吗:
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,我认为不会。 -
为什么不在主线程的调度中进行测试。在主线程以外的线程上弄乱 UI 元素是在玩火,即使它在 iOS 6 中运行,您的应用程序在 iOS 7 中也可能会严重失败......
-
因为该块在一个while循环中,该循环在另一个dispatch_async()中,否则该循环会阻塞主线程。
标签: ios uikit grand-central-dispatch