线程安全的UIKit方法 [英] Thread-safe UIKit methods
问题描述
我正在尝试确切地知道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类在单独的线程上使用很有趣,例如 UIImage
, UIColor
等。
推荐答案
来自Apple的文档:
注意:对于大多数情况下,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屋!