Important: Do not use an actor for your SwiftUI data models 重要提示:请勿将角色用于 SwiftUI 数据模型
Swift’s actors allow us to share data in multiple parts of our app without causing problems with concurrency, because they automatically ensure two pieces of code cannot...
What’s the difference between actors, classes, and structs? Actors、Classes和 Structs 之间有什么区别?
Swift provides four concrete nominal types for defining custom objects: actors, classes, structs, and enums. Each of these works a little differently from the others, but the first...
What is actor reentrancy and how can it cause problems? 什么是 actor 重入性,它如何导致问题?
Actor-isolated functions are reentrant, which means it's possible for one piece of work to begin before a previous piece of work completes. This opens the possibility of subtle bug...
What is actor hopping and how can it cause problems? 什么是 actor 跳转,它如何导致问题?
When a thread pauses work on one actor to start work on another actor instead, we call it actor hopping, and it will happen any time one actor calls another.当线程暂停对一个 a...
Understanding how global actor inference works 了解全局参与者推理的工作原理
Apple explicitly annotates many of its types as being @MainActor, including most UIKit types such as UIView and UIButton. However, for a while the Swift team da...
Who decides which actor code runs on? 谁决定在哪个 actor 代码上运行?
One common confusion with actors comes in deciding exactly where code runs, because just adding @MainActor and hoping for the best is rarely good enough.与 Actor 的一个常...
How to use @MainActor to run code on the main queue 如何使用 @MainActor 在主队列上运行代码
@MainActor is a global actor that uses the main queue for executing its work. In practice, this means methods or types marked with @MainActor can (for the most part)...
How to make parts of an actor nonisolated 如何使 actor 的各个部分非隔离
All methods and mutable properties inside an actor are isolated to that actor by default, which means they cannot be accessed directly from code that’s external to the actor. Acce...
How to make function parameters isolated 如何隔离函数参数
Any properties and methods that belong to an actor are isolated to that actor, but you can make external functions isolated to an actor if you want. This allows the funct...
Understanding actor initialization 了解 actor 初始化
Swift's actors run on their own executor most of the time, so they manage how and where their work is done. However, during the actor's initialization its executor isn't ready to t...