排序
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 ...
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...
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...
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...
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...
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...
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 的一个常...
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...