Actors共12篇
What is an actor and why does Swift have them? 什么是 actor,为什么 Swift 有它们?-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
90
How to create and use an actor in Swift 如何在 Swift 中创建和使用 actor-Stewed Noodles 资源

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 ...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
170
Understanding actor initialization 了解 actor 初始化-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
110
How to make function parameters isolated 如何隔离函数参数-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
270
How to make parts of an actor nonisolated 如何使 actor 的各个部分非隔离-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
140
How to use @MainActor to run code on the main queue 如何使用 @MainActor 在主队列上运行代码-Stewed Noodles 资源

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)...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
160
Who decides which actor code runs on? 谁决定在哪个 actor 代码上运行?-Stewed Noodles 资源

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 的一个常...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
80
Understanding how global actor inference works 了解全局参与者推理的工作原理-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
100
What is actor hopping and how can it cause problems? 什么是 actor 跳转,它如何导致问题?-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
60
What is actor reentrancy and how can it cause problems? 什么是 actor 重入性,它如何导致问题?-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
80