<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Actor - 标签 - 宋明的博客</title><link>https://apolla.cc/tags/actor/</link><description>宋明的博客</description><generator>Hugo 0.170.0 &amp; FixIt v1.0.0-rc.5-mwimukpl</generator><language>zh-cn</language><lastBuildDate>Fri, 19 Apr 2024 15:20:05 +0800</lastBuildDate><atom:link href="https://apolla.cc/tags/actor/index.xml" rel="self" type="application/rss+xml"/><item><title>4.2 @globalActor、@MainActor 的使用</title><link>https://apolla.cc/posts/4.2-@globalactor@mainactor-%E7%9A%84%E4%BD%BF%E7%94%A8/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/4.2-@globalactor@mainactor-%E7%9A%84%E4%BD%BF%E7%94%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;h1 class="heading-element" id="globalactor"&gt;&lt;span&gt;GlobalActor&lt;/span&gt;&#10; &lt;a href="#globalactor" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;状态隔离使得 actor 成为在并发环境中安全使用的引用类型，但它的作用范围仅限于单个 actor 类型。如果某些变量、函数分散在不同的地方，actor 无法将它们置于同一个隔离环境中。因此，Swift 引入了 &lt;a href="https://developer.apple.com/documentation/swift/globalactor" target="_blank" rel="external nofollow noopener noreferrer"&gt;GlobalActor 协议&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;，将状态隔离的概念扩展至全局范围。&lt;/p&gt;</description></item></channel></rss>