线程安全的 UIKit 方法 [英] Thread-safe UIKit methods

查看:19
本文介绍了线程安全的 UIKit 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出在 iOS 4.0 上的 UIKit 中哪些方法(名称!)成为线程安全的.

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

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

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?

有趣的是在单独的线程上使用的 UIKit 类很有趣,例如 UIImageUIColor 等.

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

推荐答案

来自苹果的文档:

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

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.

因此,您真的不应该在后台线程上与 UIKit 中的任何内容进行交互.

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

这篇关于线程安全的 UIKit 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆