线程安全的 UIKit 方法

发布于 2024-11-09 11:28:15 字数 361 浏览 6 评论 0原文

我试图找出 iOS 4.0 上的 UIKit 中到底哪些方法(名称!)变得线程安全。

我搜索了苹果的文档但收效甚微。例如,使用 imageNamed: 创建的 UIImage 在其他线程上使用是不安全的(它偶尔会从主线程中抛弃它的 CGImage),而 imageWithCGImage可能是(?)。另外,我还看到声称 UIColor 可以安全地在主线程以外的线程上使用。

是否有一些明确的指导来说明哪些方法是安全的,哪些方法是不安全的?

编辑: 有趣的是 UIKit 类可以在单独的线程上使用,例如 UIImage、UIColor 等。

I'm trying to find out exactly what methods (names!) became thread safe in UIKit on iOS 4.0.

I've searched through Apple's docs with little success. For instance a UIImage created with imageNamed: is not safe to use on other threads (it will occasionally jettison its CGImage from the main thread), while imageWithCGImage might be(?). Also, I've seen claims that UIColor is safe to use on threads other than the main thread.

Is there some definite guide as to which methods are safe which ones isn't?

Edit:
What's interesting is UIKit classes that is interesting to use on separate threads, such as UIImage, UIColor etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡写薰衣草的香 2024-11-16 11:28:15

来自苹果的 文档

注意:在大多数情况下,UIKit 类只能在应用程序的主线程中使用。对于从 UIResponder 派生的类或涉及以任何方式操作应用程序用户界面的类来说尤其如此。

因此,您确实不应该与 UIKit 中的任何内容进行交互。 code> 在后台线程上。

From Apple's documentation:

Note: For the most part, UIKit classes should be used only from an application’s main thread. This is particularly true for classes derived from UIResponder or that involve manipulating your application’s user interface in any way.

Therefore, you really shouldn't be interacting with anything in UIKit on a background thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文