排序
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 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...
How to create and use an actor in Swift 如何在 Swift 中创建和使用 actor
Creating and using an actor in Swift takes two steps: create the type using actor rather than class or struct, then use await when accessing its ...
What is an actor and why does Swift have them? 什么是 actor,为什么 Swift 有它们?
Swift’s actors are conceptually like classes that are safe to use in concurrent environments. This safety is made possible because Swift automatically ensures no two pieces of cod...
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 的一个常...