Thread-safe UIKit methods(线程安全的 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 类很有趣,例如 UIImage
、UIColor
等.
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 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:线程安全的 UIKit 方法


- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01