本文涉及到的几个问题来源于一次面试经历 ,当时回答的一塌糊涂,所以回来就看看官方文档和一些博客文章,并问下同学看看他们如何回答这几个问题.
希望各位 iOS 开发同学,在学习使用 Cocoa的一些 Framework 时多看看一些官方文档说明,有时候官方文档都有明确说明,我就是没有看, so 我面试时回答不出来.
声明 : 本文代码部分来源于 objc 中国 View-Layer 协作 https://objccn.io/issue-12-4/
GitHub : https://github.com/ZhaoBingDong/CAAnimaiton
一 : 为什么跟 UI 相关的 API 要在主线程 (个人理解)
```
Note
For the most part, use UIKit classes only from your app’s main thread. This is particularly true for classes derived from UIResponder or that involve manipulating your app’s user interface in any way.
在大多数的时候 , 在你的 app 里使用 UIKit 的类只能在主线程. 尤其适用于类UIResponder源于或涉及操纵你的应用程序的用户界面。
苹果 Foundation 和 UIKit 大部分 API 不是线程安全的 因为程序涉及到多线程地方毕竟是少数应用场景 苹果给每个方法属性加这种线程锁 线程同步锁 自旋锁 什么的 太麻烦
希望各位 iOS 开发同学,在学习使用 Cocoa的一些 Framework 时多看看一些官方文档说明,有时候官方文档都有明确说明,我就是没有看, so 我面试时回答不出来.
声明 : 本文代码部分来源于 objc 中国 View-Layer 协作 https://objccn.io/issue-12-4/
GitHub : https://github.com/ZhaoBingDong/CAAnimaiton
一 : 为什么跟 UI 相关的 API 要在主线程 (个人理解)
```
Note
For the most part, use UIKit classes only from your app’s main thread. This is particularly true for classes derived from UIResponder or that involve manipulating your app’s user interface in any way.
在大多数的时候 , 在你的 app 里使用 UIKit 的类只能在主线程. 尤其适用于类UIResponder源于或涉及操纵你的应用程序的用户界面。
苹果 Foundation 和 UIKit 大部分 API 不是线程安全的 因为程序涉及到多线程地方毕竟是少数应用场景 苹果给每个方法属性加这种线程锁 线程同步锁 自旋锁 什么的 太麻烦