<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SwiftUI - 分类 - 宋明的博客</title><link>https://apolla.cc/categories/swiftui/</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:06 +0800</lastBuildDate><atom:link href="https://apolla.cc/categories/swiftui/index.xml" rel="self" type="application/rss+xml"/><item><title>1.5 SwiftUI 中的属性包装器</title><link>https://apolla.cc/posts/1.5-swiftui-%E4%B8%AD%E7%9A%84%E5%B1%9E%E6%80%A7%E5%8C%85%E8%A3%85%E5%99%A8/</link><pubDate>Wed, 11 Oct 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.5-swiftui-%E4%B8%AD%E7%9A%84%E5%B1%9E%E6%80%A7%E5%8C%85%E8%A3%85%E5%99%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;以下内容适用于 iOS 16/macOS 13 以上的系统，iOS 17/macOS 14 新增的 &lt;a href="https://developer.apple.com/documentation/observation" target="_blank" rel="external nofollow noopener noreferrer"&gt;Observation&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; 框架简化了 SwiftUI 的状态管理，苹果的文档有非常详细的使用说明和迁移教程，笔者也写了一篇关于 Observation 的文章以供参考：&lt;a href="https://www.woter.xyz/blog/ios/swiftui/swiftui-observation-combine" target="_blank" rel="external nofollow noopener noreferrer"&gt;《有了 Observation，SwiftUI 还需要 Combine 吗》&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;&#10;&lt;/blockquote&gt;</description></item><item><title>1.3.3 模态（Modal）</title><link>https://apolla.cc/posts/1.3.3-%E6%A8%A1%E6%80%81modal/</link><pubDate>Tue, 10 Oct 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.3.3-%E6%A8%A1%E6%80%81modal/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;模态是除导航之外的另一种重要的信息呈现方式，它通常以一种临时的界面和用户交互。如果把导航栈内的界面比作“主线”的话，模态就是分出来的“支线”。模态视图完成它的使命后，用户最终会回归至“主线”情景。&lt;/p&gt;&#10;&lt;p&gt;关于模态的更多设计语言以及使用场景，可以参考 &lt;a href="https://developer.apple.com/design/human-interface-guidelines/patterns/modality" target="_blank" rel="external nofollow noopener noreferrer"&gt;《人机界面指南》&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><item><title>4.3 图表（Charts）</title><link>https://apolla.cc/posts/4.3-%E5%9B%BE%E8%A1%A8charts/</link><pubDate>Tue, 10 Oct 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/4.3-%E5%9B%BE%E8%A1%A8charts/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="基础"&gt;&lt;span&gt;基础&lt;/span&gt;&#10; &lt;a href="#%e5%9f%ba%e7%a1%80" 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;&lt;a href="https://developer.apple.com/documentation/charts" target="_blank" rel="external nofollow noopener noreferrer"&gt;Charts&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; 是 iOS 16/macOS 13 的新特性，用于构建各种精美的图表，如柱状图、散点图、曲线图等。&lt;/p&gt;</description></item><item><title>1.4 SwiftUI 视图管理机制</title><link>https://apolla.cc/posts/1.4-swiftui-%E8%A7%86%E5%9B%BE%E7%AE%A1%E7%90%86%E6%9C%BA%E5%88%B6/</link><pubDate>Wed, 02 Aug 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.4-swiftui-%E8%A7%86%E5%9B%BE%E7%AE%A1%E7%90%86%E6%9C%BA%E5%88%B6/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="视图的身份标识identity"&gt;&lt;span&gt;视图的身份标识（Identity）&lt;/span&gt;&#10; &lt;a href="#%e8%a7%86%e5%9b%be%e7%9a%84%e8%ba%ab%e4%bb%bd%e6%a0%87%e8%af%86identity" 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;在 UIKit/AppKit 的世界，UIView/NSView 实例是引用类型（class），程序通过指针来引用和区分对象。要实现界面的更新，我们首先需要找到对应的视图，然后下达相应的指令，比如改变视图的位置或者颜色，然后界面才会随之更新，这是典型的命令式编程。&lt;/p&gt;</description></item><item><title>3.5 滑动视图（ScrollView）</title><link>https://apolla.cc/posts/3.5-%E6%BB%91%E5%8A%A8%E8%A7%86%E5%9B%BEscrollview/</link><pubDate>Tue, 25 Jul 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.5-%E6%BB%91%E5%8A%A8%E8%A7%86%E5%9B%BEscrollview/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="基础"&gt;&lt;span&gt;基础&lt;/span&gt;&#10; &lt;a href="#%e5%9f%ba%e7%a1%80" 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;ScrollView 初始化方法如下：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;init(&#10; _ axes: Axis.Set = .vertical,&#10; showsIndicators: Bool = true,&#10; content: () -&amp;gt; Content&#10;)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;axes&lt;/code&gt; 用于指定滑动的方向，默认是垂直方向。&lt;/p&gt;</description></item><item><title>2.2 图片</title><link>https://apolla.cc/posts/2.2-%E5%9B%BE%E7%89%87/</link><pubDate>Mon, 24 Jul 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.2-%E5%9B%BE%E7%89%87/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="image"&gt;&lt;span&gt;Image&lt;/span&gt;&#10; &lt;a href="#image" 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;&lt;a href="https://developer.apple.com/documentation/swiftui/image" target="_blank" rel="external nofollow noopener noreferrer"&gt;Image&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; 用于展示图片，它可以加载资源包（Bundle）中的图片和系统内置的图标。&lt;/p&gt;</description></item><item><title>4.4 基础动画</title><link>https://apolla.cc/posts/4.4-%E5%9F%BA%E7%A1%80%E5%8A%A8%E7%94%BB/</link><pubDate>Mon, 24 Jul 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/4.4-%E5%9F%BA%E7%A1%80%E5%8A%A8%E7%94%BB/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;视图是数据状态的反映，状态的更新会驱动视图的更新。如果没有动画过渡，视图的变化会显得突兀。SwiftUI 提供了几种基于状态的动画，这些都是非常常用和基础的添加动画的方式。&lt;/p&gt;&#10;&lt;h1 class="heading-element" id="animation-方法"&gt;&lt;span&gt;.animation 方法&lt;/span&gt;&#10; &lt;a href="#animation-%e6%96%b9%e6%b3%95" 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;修饰器方法 &lt;a href="https://developer.apple.com/documentation/swiftui/view/animation(_:value:)" target="_blank" rel="external nofollow noopener noreferrer"&gt;animation(_:value:)&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><item><title>4.5 转场动画</title><link>https://apolla.cc/posts/4.5-%E8%BD%AC%E5%9C%BA%E5%8A%A8%E7%94%BB/</link><pubDate>Mon, 24 Jul 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/4.5-%E8%BD%AC%E5%9C%BA%E5%8A%A8%E7%94%BB/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="内置转场动画"&gt;&lt;span&gt;内置转场动画&lt;/span&gt;&#10; &lt;a href="#%e5%86%85%e7%bd%ae%e8%bd%ac%e5%9c%ba%e5%8a%a8%e7%94%bb" 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;转场动画用于视图的添加、移除，使用如下方法为视图添加转场：&lt;/p&gt;</description></item><item><title>3.6 列表（List）</title><link>https://apolla.cc/posts/3.6-%E5%88%97%E8%A1%A8list/</link><pubDate>Mon, 05 Jun 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.6-%E5%88%97%E8%A1%A8list/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="list"&gt;&lt;span&gt;List&lt;/span&gt;&#10; &lt;a href="#list" 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;h2 class="heading-element" id="构建"&gt;&lt;span&gt;构建&lt;/span&gt;&#10; &lt;a href="#%e6%9e%84%e5%bb%ba" 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;/h2&gt;&lt;h3 class="heading-element" id="基础"&gt;&lt;span&gt;基础&lt;/span&gt;&#10; &lt;a href="#%e5%9f%ba%e7%a1%80" 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;/h3&gt;&lt;p&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/list" target="_blank" rel="external nofollow noopener noreferrer"&gt;List&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><item><title>2.3 视图样式与行为</title><link>https://apolla.cc/posts/2.3-%E8%A7%86%E5%9B%BE%E6%A0%B7%E5%BC%8F%E4%B8%8E%E8%A1%8C%E4%B8%BA/</link><pubDate>Sat, 06 May 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.3-%E8%A7%86%E5%9B%BE%E6%A0%B7%E5%BC%8F%E4%B8%8E%E8%A1%8C%E4%B8%BA/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="字体"&gt;&lt;span&gt;字体&lt;/span&gt;&#10; &lt;a href="#%e5%ad%97%e4%bd%93" 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;&lt;strong&gt;SwiftUI&lt;/strong&gt; 内置了许多不同大小的字体，它们具有动态缩放特性：&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;在不同设备上动态缩放。&lt;/li&gt;&#10;&lt;li&gt;在支持动态缩放的 App 中，根据手机设置的字体大小动态缩放。&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;span style="background: #007BFF; color: white; padding: 3px 10px; border-radius: 5px"&gt;&amp;gt; 查看示例&lt;/span&gt;&lt;/p&gt;</description></item><item><title>2.8 使用 UIKit、AppKit</title><link>https://apolla.cc/posts/2.8-%E4%BD%BF%E7%94%A8-uikitappkit/</link><pubDate>Thu, 23 Feb 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.8-%E4%BD%BF%E7%94%A8-uikitappkit/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;SwiftUI 目前仍在发展中，相比古老而健壮的 UIKit/AppKit，它相对年轻，在生产实践中，有时我们需要借助 UIKit/AppKit 来实现 SwiftUI 难以实现的功能。&lt;/p&gt;&#10;&lt;p&gt;以下仅以 UIKit 为例进行说明，AppKit 与此类似。&lt;/p&gt;&#10;&lt;h1 class="heading-element" id="使用-uikit"&gt;&lt;span&gt;使用 UIKit&lt;/span&gt;&#10; &lt;a href="#%e4%bd%bf%e7%94%a8-uikit" 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;h2 class="heading-element" id="uiviewrepresentable"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/uiviewrepresentable" target="_blank" rel="external nofollow noopener noreferrer"&gt;UIViewRepresentable&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;/span&gt;&#10; &lt;a href="#uiviewrepresentable" 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;/h2&gt;&lt;p&gt;SwiftUI 通过 UIViewRepresentable 协议可以调用 UIKit 中的视图，比如想使用 UISearchBar：&lt;/p&gt;</description></item><item><title>5.3 自定义手势</title><link>https://apolla.cc/posts/5.3-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%89%8B%E5%8A%BF/</link><pubDate>Sun, 29 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/5.3-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%89%8B%E5%8A%BF/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;&lt;span style="background: #007BFF; color: white; padding: 3px 10px; border-radius: 5px"&gt;&amp;gt; 查看示例&lt;/span&gt;&lt;/p&gt;&#10;&lt;p&gt;SwiftUI 内置了一些常用手势，它们都实现了 &lt;a href="https://developer.apple.com/documentation/swiftui/gesture" target="_blank" rel="external nofollow noopener noreferrer"&gt;Gesture&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;&#10;&lt;p&gt;如果需要自定义手势，也需要实现该协议，其声明如下：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;public protocol Gesture {&#10;&#10; /// The type representing the gesture&amp;#39;s value.&#10; associatedtype Value&#10;&#10; /// The type of gesture representing the body of `Self`.&#10; associatedtype Body : Gesture&#10;&#10; /// The content and behavior of the gesture.&#10; var body: Self.Body { get }&#10;}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;和 View 协议类似，body 属性是必须实现的，它的类型由关联类型 Body 定义。另一个关联类型 Value 用于保存手势的状态，在 &lt;code&gt;.onChange&lt;/code&gt; 、 &lt;code&gt;.udpating&lt;/code&gt; 等监听方法中返回该状态。&lt;/p&gt;</description></item><item><title>5.1 常见手势</title><link>https://apolla.cc/posts/5.1-%E5%B8%B8%E8%A7%81%E6%89%8B%E5%8A%BF/</link><pubDate>Sat, 28 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/5.1-%E5%B8%B8%E8%A7%81%E6%89%8B%E5%8A%BF/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h2 class="heading-element" id="tapgesturespatialtapgesture"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/tapgesture" target="_blank" rel="external nofollow noopener noreferrer"&gt;TapGesture&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;a href="https://developer.apple.com/documentation/swiftui/spatialtapgesture" target="_blank" rel="external nofollow noopener noreferrer"&gt;SpatialTapGesture&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;/span&gt;&#10; &lt;a href="#tapgesturespatialtapgesture" 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;/h2&gt;&lt;p&gt;要为视图添加点击手势，可以使用 &lt;a href="https://developer.apple.com/documentation/swiftui/view/gesture(_:including:)" target="_blank" rel="external nofollow noopener noreferrer"&gt;gesture(_:including:)&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; 绑定一个 TapGesture 实例至视图，也可以直接在视图上使用 &lt;code&gt;.onTapGesture&lt;/code&gt; 方法。&lt;/p&gt;</description></item><item><title>5.2 手势的管理</title><link>https://apolla.cc/posts/5.2-%E6%89%8B%E5%8A%BF%E7%9A%84%E7%AE%A1%E7%90%86/</link><pubDate>Sat, 28 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/5.2-%E6%89%8B%E5%8A%BF%E7%9A%84%E7%AE%A1%E7%90%86/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="手势的状态监听"&gt;&lt;span&gt;手势的状态监听&lt;/span&gt;&#10; &lt;a href="#%e6%89%8b%e5%8a%bf%e7%9a%84%e7%8a%b6%e6%80%81%e7%9b%91%e5%90%ac" 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;《常见手势》 演示了通过 &lt;code&gt;.onChanged&lt;/code&gt; 和 &lt;code&gt;.onEnded&lt;/code&gt; 分别监听手势的变化和结束。&lt;/p&gt;</description></item><item><title>4.7 动画的进阶使用</title><link>https://apolla.cc/posts/4.7-%E5%8A%A8%E7%94%BB%E7%9A%84%E8%BF%9B%E9%98%B6%E4%BD%BF%E7%94%A8/</link><pubDate>Tue, 17 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/4.7-%E5%8A%A8%E7%94%BB%E7%9A%84%E8%BF%9B%E9%98%B6%E4%BD%BF%E7%94%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;h1 class="heading-element" id="transaction"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/transaction" target="_blank" rel="external nofollow noopener noreferrer"&gt;Transaction&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;/span&gt;&#10; &lt;a href="#transaction" 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;事务（Transaction）是当前状态更新的上下文，包含状态变化过程中的动画。&lt;/p&gt;</description></item><item><title>4.6 动画原理</title><link>https://apolla.cc/posts/4.6-%E5%8A%A8%E7%94%BB%E5%8E%9F%E7%90%86/</link><pubDate>Fri, 13 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/4.6-%E5%8A%A8%E7%94%BB%E5%8E%9F%E7%90%86/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;h1 class="heading-element" id="animatable-协议"&gt;&lt;span&gt;Animatable 协议&lt;/span&gt;&#10; &lt;a href="#animatable-%e5%8d%8f%e8%ae%ae" 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;我们之所以能看见动画的效果，是因为 SwiftUI 在视图变化的首尾状态之间不断地重绘视图，一系列静态视图因“视觉暂留”作用而造成一种连续的视觉印象，让我们感觉视图动起来了，这其实也是电影的原理。比如一个视图需要从透明度 0 变成 1，SwiftUI 会在 0 和 1 之间不断地作插值运算，不断重绘不同透明度的视图（0，0.1，0.2，0.3 &amp;hellip; 1.0），直到视图不再变化。如果使用 &lt;code&gt;.linear&lt;/code&gt; 指定动画效果，那么视图的重绘过程是匀速的，如果使用 &lt;code&gt;.easeOut&lt;/code&gt;，那么重绘的过程是先快后慢，以此类推。&lt;/p&gt;</description></item><item><title>4.2 图形的绘制</title><link>https://apolla.cc/posts/4.2-%E5%9B%BE%E5%BD%A2%E7%9A%84%E7%BB%98%E5%88%B6/</link><pubDate>Mon, 09 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/4.2-%E5%9B%BE%E5%BD%A2%E7%9A%84%E7%BB%98%E5%88%B6/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;h1 class="heading-element" id="canvas-的使用"&gt;&lt;span&gt;Canvas 的使用&lt;/span&gt;&#10; &lt;a href="#canvas-%e7%9a%84%e4%bd%bf%e7%94%a8" 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;Canvas 字面意思就是“画布”，在这个画布上可以绘制各种图形。与 Shape 不同的是，Canvas 支持即时绘制，比如用户可以使用手指在屏幕上涂鸦。&lt;/p&gt;</description></item><item><title>3.9 自定义布局（Layout）</title><link>https://apolla.cc/posts/3.9-%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B8%83%E5%B1%80layout/</link><pubDate>Sat, 07 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.9-%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B8%83%E5%B1%80layout/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;SwiftUI 内置了丰富的布局容器，也支持简单的布局调整，它们能够解决大多数常用的布局需求。但仍然有所限制，比如 HStack 或者 VStack，它们只能在单一线性轴上进行布局，Grid 虽然可以兼顾横向和纵向，但子视图的位置不能随意调整。&lt;/p&gt;&#10;&lt;p&gt;而 Layout 协议支持自定义布局，我们可以使用它随心所欲地实现各种纷繁的布局效果。&lt;/p&gt;</description></item><item><title>4.1 形状（Shapes）的使用</title><link>https://apolla.cc/posts/4.1-%E5%BD%A2%E7%8A%B6shapes%E7%9A%84%E4%BD%BF%E7%94%A8/</link><pubDate>Sat, 07 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/4.1-%E5%BD%A2%E7%8A%B6shapes%E7%9A%84%E4%BD%BF%E7%94%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="常用的内置形状及样式"&gt;&lt;span&gt;常用的内置形状及样式&lt;/span&gt;&#10; &lt;a href="#%e5%b8%b8%e7%94%a8%e7%9a%84%e5%86%85%e7%bd%ae%e5%bd%a2%e7%8a%b6%e5%8f%8a%e6%a0%b7%e5%bc%8f" 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;h2 class="heading-element" id="内置形状"&gt;&lt;span&gt;内置形状&lt;/span&gt;&#10; &lt;a href="#%e5%86%85%e7%bd%ae%e5%bd%a2%e7%8a%b6" 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;/h2&gt;&lt;p&gt;SwiftUI 内置了一些常用的形状，比如矩形、椭圆、正圆等。&lt;/p&gt;</description></item><item><title>3.7 表格（Table）</title><link>https://apolla.cc/posts/3.7-%E8%A1%A8%E6%A0%BCtable/</link><pubDate>Fri, 06 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.7-%E8%A1%A8%E6%A0%BCtable/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;</description></item><item><title>3.11 SwiftUI 布局总结</title><link>https://apolla.cc/posts/3.11-swiftui-%E5%B8%83%E5%B1%80%E6%80%BB%E7%BB%93/</link><pubDate>Thu, 05 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.11-swiftui-%E5%B8%83%E5%B1%80%E6%80%BB%E7%BB%93/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;pre&gt;&lt;code&gt;fileprivate struct ViewTransforming: View {&#10; @State private var aspectRatio: CGFloat = 1.0&#10; &#10; var body: some View {&#10; GroupBox(&amp;#34;aspectRatio&amp;#34;) {&#10; Rectangle()&#10; .fill(.blue.gradient)&#10; .aspectRatio(aspectRatio, contentMode: .fit)&#10; .frame(width: 80)&#10; LabeledContent(&amp;#34;aspectRatio: \(aspectRatio, specifier: &amp;#34;%.1f&amp;#34;)&amp;#34;) {&#10; Slider(value: $aspectRatio, in: 0.5...2.0)&#10; }&#10; }&#10; }&#10;}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/57243677/proportional-height-or-width-in-swiftui" target="_blank" rel="external nofollow noopener noreferrer"&gt;https://stackoverflow.com/questions/57243677/proportional-height-or-width-in-swiftui&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;&#10;&lt;p&gt;静态渲染适用于轻量的数据展示，比如 HStack、Grid 等，它们的内容和尺寸都相对固定。SwiftUI 会计算它们包含的所有视图，无论该视图是在屏幕内或屏幕外，如果有少量的视图需要渲染，使用它们是非常合适的。&lt;/p&gt;</description></item><item><title>3.8 共享布局信息</title><link>https://apolla.cc/posts/3.8-%E5%85%B1%E4%BA%AB%E5%B8%83%E5%B1%80%E4%BF%A1%E6%81%AF/</link><pubDate>Thu, 05 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.8-%E5%85%B1%E4%BA%AB%E5%B8%83%E5%B1%80%E4%BF%A1%E6%81%AF/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="geometryreader"&gt;&lt;span&gt;GeometryReader&lt;/span&gt;&#10; &lt;a href="#geometryreader" 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;&lt;a href="https://developer.apple.com/documentation/swiftui/geometryreader" target="_blank" rel="external nofollow noopener noreferrer"&gt;GeometryReader&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;a href="https://developer.apple.com/documentation/swiftui/geometryproxy" target="_blank" rel="external nofollow noopener noreferrer"&gt;GeometryProxy&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><item><title>3.2.1 视图组</title><link>https://apolla.cc/posts/3.2.1-%E8%A7%86%E5%9B%BE%E7%BB%84/</link><pubDate>Wed, 04 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.2.1-%E8%A7%86%E5%9B%BE%E7%BB%84/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="group"&gt;&lt;span&gt;Group&lt;/span&gt;&#10; &lt;a href="#group" 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;前面提到过 SwiftUI 能够将各种视图组合在一起，得益于结果生成器，关于结果生成器，参考 《Swift 中的 Result builders》 。&lt;/p&gt;</description></item><item><title>3.4 格子（Grids）</title><link>https://apolla.cc/posts/3.4-%E6%A0%BC%E5%AD%90grids/</link><pubDate>Wed, 04 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.4-%E6%A0%BC%E5%AD%90grids/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="grid"&gt;&lt;span&gt;Grid&lt;/span&gt;&#10; &lt;a href="#grid" 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;&lt;a href="https://developer.apple.com/documentation/swiftui/grid" target="_blank" rel="external nofollow noopener noreferrer"&gt;Grid&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;a href="https://developer.apple.com/documentation/swiftui/gridrow" target="_blank" rel="external nofollow noopener noreferrer"&gt;GridRow&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; 是 iOS 16/macOS 13 新出的功能，用于快速构建静态格子视图。&lt;/p&gt;</description></item><item><title>3.3 布局的调整</title><link>https://apolla.cc/posts/3.3-%E5%B8%83%E5%B1%80%E7%9A%84%E8%B0%83%E6%95%B4/</link><pubDate>Fri, 23 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.3-%E5%B8%83%E5%B1%80%E7%9A%84%E8%B0%83%E6%95%B4/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;调整视图布局的方法是多样的，本文主要介绍通过调整 view 的尺寸、位置以及对齐方式等来实现布局的基础调整，在实际开发中，需要选择合适的方法来实现不同的布局效果。除此以外，后面还会介绍自定义 layout 来实现更加高级和灵活地布局。&lt;/p&gt;&#10;&lt;h1 class="heading-element" id="尺寸"&gt;&lt;span&gt;尺寸&lt;/span&gt;&#10; &lt;a href="#%e5%b0%ba%e5%af%b8" 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;h2 class="heading-element" id="padding"&gt;&lt;span&gt;padding&lt;/span&gt;&#10; &lt;a href="#padding" 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;/h2&gt;&lt;p&gt;SwiftUI 提供了多个 padding 方法，可以方便地调整视图各个方向上的内边距，从而影响布局和空间的分配。&lt;/p&gt;</description></item><item><title>3.2 堆叠（Stacks）</title><link>https://apolla.cc/posts/3.2-%E5%A0%86%E5%8F%A0stacks/</link><pubDate>Thu, 22 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.2-%E5%A0%86%E5%8F%A0stacks/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="hstackvstackzstack"&gt;&lt;span&gt;HStack、VStack、ZStack&lt;/span&gt;&#10; &lt;a href="#hstackvstackzstack" 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;&lt;a href="https://developer.apple.com/documentation/swiftui/hstack" target="_blank" rel="external nofollow noopener noreferrer"&gt;HStack&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;a href="https://developer.apple.com/documentation/swiftui/vstack" target="_blank" rel="external nofollow noopener noreferrer"&gt;VStack&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;a href="https://developer.apple.com/documentation/swiftui/zstack" target="_blank" rel="external nofollow noopener noreferrer"&gt;ZStack&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; 分别可以在三个线性轴 x、y、z 方向上组合视图。&lt;/p&gt;</description></item><item><title>3.1 SwiftUI 布局思想简介</title><link>https://apolla.cc/posts/3.1-swiftui-%E5%B8%83%E5%B1%80%E6%80%9D%E6%83%B3%E7%AE%80%E4%BB%8B/</link><pubDate>Wed, 21 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.1-swiftui-%E5%B8%83%E5%B1%80%E6%80%9D%E6%83%B3%E7%AE%80%E4%BB%8B/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;SwiftUI 的布局过程大致如下：&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;父视图为子视图提供布局空间。&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;若指定了尺寸，父视图提供的布局空间就是指定的尺寸范围。&lt;/li&gt;&#10;&lt;li&gt;若没指定尺寸：&#10;&lt;ul&gt;&#10;&lt;li&gt;若父视图是无边界的，比如 Color 还有下面提到的 ScrollView，它的尺寸默认是无限大（这里的无限大指可以利用的一切空间，下同）。&lt;/li&gt;&#10;&lt;li&gt;若父视图是有边界的，比如 HStack、VStack 等，它的尺寸取决于子视图的尺寸。&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;子视图根据自身内容计算尺寸，并将该信息提供给父视图。&lt;/p&gt;&#10;&lt;p&gt;SwiftUI 中的视图层级类似树状结构，对每个节点视图的 body 属性的计算是个递归的过程，终止条件是遇到 body 属性为 Never 的视图，它们又称为原始视图，是这颗树上的叶子结点。这里提到的父子关系并非绝对概念，子视图可能也作为其它视图的父视图，父子其实是个相对概念。&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;父视图根据子视图提供的尺寸信息计算自身尺寸并对子视图进行布局。&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;若父视图指定了尺寸，则根据指定的尺寸对子视图进行布局。&lt;/li&gt;&#10;&lt;li&gt;若父视图没指定尺寸，则根据子视图提供的尺寸信息计算自身的尺寸并对子视图进行布局。父视图在计算自身尺寸时如果它本身就是无边界的，那么它的尺寸不受子视图的影响。&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ol&gt;</description></item><item><title>2.6 视图生命周期方法</title><link>https://apolla.cc/posts/2.6-%E8%A7%86%E5%9B%BE%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E6%96%B9%E6%B3%95/</link><pubDate>Tue, 20 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.6-%E8%A7%86%E5%9B%BE%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E6%96%B9%E6%B3%95/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="onappear"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/view/onappear(perform:)" target="_blank" rel="external nofollow noopener noreferrer"&gt;onAppear&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;/span&gt;&#10; &lt;a href="#onappear" 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;在视图即将出现时会触发 onAppear 方法。&lt;/p&gt;&#10;&lt;p&gt;&lt;span style="background: #007BFF; color: white; padding: 3px 10px; border-radius: 5px"&gt;&amp;gt; 查看示例&lt;/span&gt;&lt;/p&gt;</description></item><item><title>2.7 自定义视图</title><link>https://apolla.cc/posts/2.7-%E8%87%AA%E5%AE%9A%E4%B9%89%E8%A7%86%E5%9B%BE/</link><pubDate>Tue, 20 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.7-%E8%87%AA%E5%AE%9A%E4%B9%89%E8%A7%86%E5%9B%BE/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="自定义-view"&gt;&lt;span&gt;自定义 view&lt;/span&gt;&#10; &lt;a href="#%e8%87%aa%e5%ae%9a%e4%b9%89-view" 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;SwiftUI 中的视图都是实现 View 协议的结构体，比如需要自定义一个垂直布局的 Label：&lt;/p&gt;</description></item><item><title>2.4.5 控件-样式</title><link>https://apolla.cc/posts/2.4.5-%E6%8E%A7%E4%BB%B6-%E6%A0%B7%E5%BC%8F/</link><pubDate>Mon, 19 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.4.5-%E6%8E%A7%E4%BB%B6-%E6%A0%B7%E5%BC%8F/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="色调"&gt;&lt;span&gt;色调&lt;/span&gt;&#10; &lt;a href="#%e8%89%b2%e8%b0%83" 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;在 《控件-指示器》 一文提到过可以通过 &lt;code&gt;.tint&lt;/code&gt; 方法覆盖程序设置的 accentColor 来给控件指定主色调，但并非所有控件都能生效，比如使用渐变色样式时，无法应用该样式的控件会采用渐变色的第一个颜色进行渲染。&lt;/p&gt;</description></item><item><title>2.5 菜单与命令</title><link>https://apolla.cc/posts/2.5-%E8%8F%9C%E5%8D%95%E4%B8%8E%E5%91%BD%E4%BB%A4/</link><pubDate>Mon, 19 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.5-%E8%8F%9C%E5%8D%95%E4%B8%8E%E5%91%BD%E4%BB%A4/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;Menu 也是一种常用控件，用于创建菜单视图。Button、Toggle、Picker 等常用控件都可以作为 Menu 的子控件，Menu 本身还支持嵌套使用。&lt;/p&gt;&#10;&lt;p&gt;&lt;span style="background: #007BFF; color: white; padding: 3px 10px; border-radius: 5px"&gt;&amp;gt; 查看示例&lt;/span&gt;&lt;/p&gt;&#10;&lt;p&gt;Menu 的构建方法中有一个支持 primaryAction 的闭包，没有添加它时，单击 menu 就会弹出菜单，添加之后，单击 menu 的事件就会成为 primaryAction，长按（iOS）或者点击菜单下拉按钮（macOS）时才会弹出菜单。macOS 的下拉菜单按钮可以通过方法 &lt;a href="https://developer.apple.com/documentation/swiftui/view/menuindicator(_:)" target="_blank" rel="external nofollow noopener noreferrer"&gt;menuIndicator(_:)&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><item><title>2.4.4 控件-指示器</title><link>https://apolla.cc/posts/2.4.4-%E6%8E%A7%E4%BB%B6-%E6%8C%87%E7%A4%BA%E5%99%A8/</link><pubDate>Fri, 16 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.4.4-%E6%8E%A7%E4%BB%B6-%E6%8C%87%E7%A4%BA%E5%99%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="progressview"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/progressview" target="_blank" rel="external nofollow noopener noreferrer"&gt;ProgressView&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;/span&gt;&#10; &lt;a href="#progressview" 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;ProgressView 有菊花和进度条两种样式，&lt;span style="background: #007BFF; color: white; padding: 3px 10px; border-radius: 5px"&gt;&amp;gt; 查看示例&lt;/span&gt; 。&lt;/p&gt;</description></item><item><title>2.4.1 控件-按钮</title><link>https://apolla.cc/posts/2.4.1-%E6%8E%A7%E4%BB%B6-%E6%8C%89%E9%92%AE/</link><pubDate>Thu, 15 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.4.1-%E6%8E%A7%E4%BB%B6-%E6%8C%89%E9%92%AE/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="按钮样式"&gt;&lt;span&gt;按钮样式&lt;/span&gt;&#10; &lt;a href="#%e6%8c%89%e9%92%ae%e6%a0%b7%e5%bc%8f" 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;&lt;a href="https://developer.apple.com/documentation/swiftui/button" target="_blank" rel="external nofollow noopener noreferrer"&gt;Button&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; 可以通过字符串或 view 构建，需要注意的是，通过字符串构建 Button 时， &lt;code&gt;.frame&lt;/code&gt; 是无法扩大点击范围的。因为 frame 的作用是给父视图提供尺寸信息作布局用，我们可以在 frame 的基础上更改 button 的背景，但 button 自身的尺寸依然是由自身内容（字符串）决定的。对于简单的按钮可以直接通过字符串构建，系统也提供了内置的按钮样式。如需更丰富的样式，推荐使用 view 构建，或是自定义按钮样式。&lt;/p&gt;</description></item><item><title>2.4.2 控件-链接</title><link>https://apolla.cc/posts/2.4.2-%E6%8E%A7%E4%BB%B6-%E9%93%BE%E6%8E%A5/</link><pubDate>Thu, 15 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.4.2-%E6%8E%A7%E4%BB%B6-%E9%93%BE%E6%8E%A5/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="link"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/link" target="_blank" rel="external nofollow noopener noreferrer"&gt;Link&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;/span&gt;&#10; &lt;a href="#link" 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;Link 可以打开网页链接，如果通用链接（Universal Link）支持，会跳转到对应的 App 页面。&lt;/p&gt;</description></item><item><title>2.4.3 控件-选择器</title><link>https://apolla.cc/posts/2.4.3-%E6%8E%A7%E4%BB%B6-%E9%80%89%E6%8B%A9%E5%99%A8/</link><pubDate>Thu, 15 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.4.3-%E6%8E%A7%E4%BB%B6-%E9%80%89%E6%8B%A9%E5%99%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="toggle"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/toggle" target="_blank" rel="external nofollow noopener noreferrer"&gt;Toggle&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;/span&gt;&#10; &lt;a href="#toggle" 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;Toggle 是表示开关状态的控件，默认的颜色风格是绿色，使用 &lt;code&gt;.tint&lt;/code&gt; 可以改变颜色。&lt;/p&gt;</description></item><item><title>2.1.1 文本-Text</title><link>https://apolla.cc/posts/2.1.1-%E6%96%87%E6%9C%AC-text/</link><pubDate>Mon, 05 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.1.1-%E6%96%87%E6%9C%AC-text/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="字符串"&gt;&lt;span&gt;字符串&lt;/span&gt;&#10; &lt;a href="#%e5%ad%97%e7%ac%a6%e4%b8%b2" 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;SwiftUI 中涉及到字符串的地方，基本都支持普通的字符串和本地化字符串。&lt;/p&gt;</description></item><item><title>2.1.2 文本-Label</title><link>https://apolla.cc/posts/2.1.2-%E6%96%87%E6%9C%AC-label/</link><pubDate>Mon, 05 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.1.2-%E6%96%87%E6%9C%AC-label/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="构建方法"&gt;&lt;span&gt;构建方法&lt;/span&gt;&#10; &lt;a href="#%e6%9e%84%e5%bb%ba%e6%96%b9%e6%b3%95" 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;&lt;a href="https://developer.apple.com/documentation/swiftui/label" target="_blank" rel="external nofollow noopener noreferrer"&gt;Label&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><item><title>2.1.3 文本-输入</title><link>https://apolla.cc/posts/2.1.3-%E6%96%87%E6%9C%AC-%E8%BE%93%E5%85%A5/</link><pubDate>Mon, 05 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.1.3-%E6%96%87%E6%9C%AC-%E8%BE%93%E5%85%A5/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="textfield"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/textfield" target="_blank" rel="external nofollow noopener noreferrer"&gt;TextField&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;/span&gt;&#10; &lt;a href="#textfield" 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;h2 class="heading-element" id="构建及样式"&gt;&lt;span&gt;构建及样式&lt;/span&gt;&#10; &lt;a href="#%e6%9e%84%e5%bb%ba%e5%8f%8a%e6%a0%b7%e5%bc%8f" 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;/h2&gt;&lt;p&gt;TextField 具有多个构建方法，最简单的如下：&lt;/p&gt;</description></item><item><title>1.3.4 工具栏（Toolbars）</title><link>https://apolla.cc/posts/1.3.4-%E5%B7%A5%E5%85%B7%E6%A0%8Ftoolbars/</link><pubDate>Thu, 01 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.3.4-%E5%B7%A5%E5%85%B7%E6%A0%8Ftoolbars/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;SwiftUI 将 navigationBar、bottomBar、tabBar、windowToolbar 等视图的功能和样式都整合在了工具栏中，使用时调用的 api 都是以 .toolbar 开头的。&lt;/p&gt;&#10;&lt;p&gt;比如要给导航栏右侧添加一个分享按钮：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;#if os(iOS)&#10;NavigationStack {&#10; ContentView()&#10; .toolbar {&#10; ToolbarItem(placement: .navigationBarTrailing) {&#10; Button {&#10; } label: {&#10; Image(systemName: &amp;#34;square.and.arrow.up&amp;#34;)&#10; }&#10; }&#10; }&#10;}&#10;#endif&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;span style="background: #007BFF; color: white; padding: 3px 10px; border-radius: 5px"&gt;&amp;gt; 查看示例&lt;/span&gt;&lt;/p&gt;</description></item><item><title>1.3.0 TabView 的使用</title><link>https://apolla.cc/posts/1.3.0-tabview-%E7%9A%84%E4%BD%BF%E7%94%A8/</link><pubDate>Wed, 23 Nov 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.3.0-tabview-%E7%9A%84%E4%BD%BF%E7%94%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="基础使用"&gt;&lt;span&gt;基础使用&lt;/span&gt;&#10; &lt;a href="#%e5%9f%ba%e7%a1%80%e4%bd%bf%e7%94%a8" 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;&lt;a href="https://developer.apple.com/documentation/swiftui/tabview" target="_blank" rel="external nofollow noopener noreferrer"&gt;TabView&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; 等同于 UIKit 中的 UITabBar，先来看看它的基础使用：&lt;/p&gt;</description></item><item><title>1.3.2 导航之 NavigationSplitView</title><link>https://apolla.cc/posts/1.3.2-%E5%AF%BC%E8%88%AA%E4%B9%8B-navigationsplitview/</link><pubDate>Mon, 21 Nov 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.3.2-%E5%AF%BC%E8%88%AA%E4%B9%8B-navigationsplitview/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/navigationsplitview" target="_blank" rel="external nofollow noopener noreferrer"&gt;NavigationSplitView&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; 用于快速构建多栏视图，它支持在 Apple 全平台上使用。根据设备屏幕尺寸（Size Class）的差异，NavigationSplitView 的样式有所不同。&lt;/p&gt;&#10;&lt;p&gt;Size Class 分为 regular 和 compact，NavigationSplitView 相应的表现分别是分栏和导航栈。正如示例所示，在 iPhone 14 Plus 或 iPhone 14 Pro Max 机型上，竖屏时 Size Class 是 compact，导航行为就是常见的 push 和 pop。而横屏时，Size Class 是 regular，视图会变成分栏样式。&lt;/p&gt;</description></item><item><title>1.3.1 导航之 NavigationStack</title><link>https://apolla.cc/posts/1.3.1-%E5%AF%BC%E8%88%AA%E4%B9%8B-navigationstack/</link><pubDate>Mon, 05 Sep 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.3.1-%E5%AF%BC%E8%88%AA%E4%B9%8B-navigationstack/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;iOS 16 废弃了 NavigationView，使用更加灵活的 &lt;a href="https://developer.apple.com/documentation/swiftui/navigationstack" target="_blank" rel="external nofollow noopener noreferrer"&gt;NavigationStack&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;a href="https://developer.apple.com/documentation/swiftui/navigationsplitview" target="_blank" rel="external nofollow noopener noreferrer"&gt;NavigationSplitView&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; 管理导航栈。二者在 iOS、iPadOS、macOS 上均可使用，但在不同平台表现不一。后文主要演示 NavigationStack 在 iPhone、iPad 上的使用，NavigationSplitView 在 iPad、Mac 上的使用。&lt;/p&gt;</description></item><item><title>1.3 SwiftUI 中的场景</title><link>https://apolla.cc/posts/1.3-swiftui-%E4%B8%AD%E7%9A%84%E5%9C%BA%E6%99%AF/</link><pubDate>Mon, 29 Aug 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.3-swiftui-%E4%B8%AD%E7%9A%84%E5%9C%BA%E6%99%AF/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;p&gt;&lt;em&gt;鉴于 Scene 比较特殊，难以在 Eul 中内置示例，笔者为其单独创建了一个样例工程，源码：&lt;a href="https://github.com/zzzwco/resources/tree/main/eul/SampleScene" target="_blank" rel="external nofollow noopener noreferrer"&gt;Eul/SampleScene&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;/em&gt;&lt;/p&gt;&#10;&lt;p&gt;在 [[1.1.2 生命周期的演变]]中已经介绍过一些关于场景的概念了，下面逐一介绍 SwiftUI 内置的场景及其用法。&lt;/p&gt;&#10;&lt;h2 class="heading-element" id="windowgroup"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/windowgroup?changes=latest_minor" target="_blank" rel="external nofollow noopener noreferrer"&gt;WindowGroup&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;/span&gt;&#10; &lt;a href="#windowgroup" 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;/h2&gt;&lt;p&gt;这是最重要、最常用的场景，新建一个 SwiftUI 工程时，在 app 入口处就会看到如下代码：&lt;/p&gt;</description></item><item><title>1.2 生命周期的演变</title><link>https://apolla.cc/posts/1.2-%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%9A%84%E6%BC%94%E5%8F%98/</link><pubDate>Sat, 20 Aug 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.2-%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%9A%84%E6%BC%94%E5%8F%98/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;iOS 13 之前，app 的入口以及生命周期方法由 &lt;a href="https://developer.apple.com/documentation/uikit/uiapplicationdelegate" target="_blank" rel="external nofollow noopener noreferrer"&gt;UIApplicationDelegate&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;a href="https://developer.apple.com/documentation/uikit/uiwindow" target="_blank" rel="external nofollow noopener noreferrer"&gt;UIWindow&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;&#10;&lt;p&gt;iOS 13 开始，iPad 支持多窗口模式。 臃肿的 AppDelegate 不堪重负，于是它将各个窗口的管理工作分配给 &lt;a href="https://developer.apple.com/documentation/uikit/uiscenedelegate" target="_blank" rel="external nofollow noopener noreferrer"&gt;UISceneDelegate&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;&#10;&lt;p&gt;iOS 14 新增了 SwiftUI 专属的 &lt;a href="https://developer.apple.com/documentation/swiftui/app" target="_blank" rel="external nofollow noopener noreferrer"&gt;App&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; 协议，它定义了 app 的结构和行为。创建一个 SwiftUI 项目时，Xcode 默认实现了一个 App 实例：&lt;/p&gt;</description></item><item><title>1.1 App 入口与配置</title><link>https://apolla.cc/posts/1.1-app-%E5%85%A5%E5%8F%A3%E4%B8%8E%E9%85%8D%E7%BD%AE/</link><pubDate>Mon, 15 Aug 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.1-app-%E5%85%A5%E5%8F%A3%E4%B8%8E%E9%85%8D%E7%BD%AE/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="入口"&gt;&lt;span&gt;入口&lt;/span&gt;&#10; &lt;a href="#%e5%85%a5%e5%8f%a3" 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;当我们 &lt;a href="https://developer.apple.com/documentation/xcode/creating-an-xcode-project-for-an-app" target="_blank" rel="external nofollow noopener noreferrer"&gt;创建一个工程&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><item><title>1.1 App 入口与配置_副本</title><link>https://apolla.cc/posts/1.1-app-%E5%85%A5%E5%8F%A3%E4%B8%8E%E9%85%8D%E7%BD%AE_%E5%89%AF%E6%9C%AC/</link><pubDate>Mon, 15 Aug 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.1-app-%E5%85%A5%E5%8F%A3%E4%B8%8E%E9%85%8D%E7%BD%AE_%E5%89%AF%E6%9C%AC/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="入口"&gt;&lt;span&gt;入口&lt;/span&gt;&#10; &lt;a href="#%e5%85%a5%e5%8f%a3" 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;当我们 &lt;a href="https://developer.apple.com/documentation/xcode/creating-an-xcode-project-for-an-app" target="_blank" rel="external nofollow noopener noreferrer"&gt;创建一个工程&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><item><title>1.1 Swift 并发新体验</title><link>https://apolla.cc/posts/1.1-swift-%E5%B9%B6%E5%8F%91%E6%96%B0%E4%BD%93%E9%AA%8C/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/1.1-swift-%E5%B9%B6%E5%8F%91%E6%96%B0%E4%BD%93%E9%AA%8C/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;h1 class="heading-element" id="引言"&gt;&lt;span&gt;引言&lt;/span&gt;&#10; &lt;a href="#%e5%bc%95%e8%a8%80" 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;对于诞生于 2014 年的 Swift 而言，它已不再年轻。至今我还记得初次体验 Swift 时的喜悦之情，比起冗长的 OC 而言，它更加现代、简洁、优雅。但 Swift 的前期发展是野蛮而动荡的，每次发布新版本时都会导致旧项目出现大量的报错和告警，项目迁移工作令开发者苦不堪言。不得不说，Swift 诞生之初就敢于在项目中实践并运用的人，是真的猛士。我是从 Swift 4 才开始将项目逐渐从 OC 向 Swift 迁移的，到 2019 年 Swift 5 实现了 ABI 稳定时，才全面迁移至纯 Swift 开发。&lt;/p&gt;</description></item><item><title>1.2 async、await 的使用</title><link>https://apolla.cc/posts/1.2-asyncawait-%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/1.2-asyncawait-%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="asyncawait"&gt;&lt;span&gt;async/await&lt;/span&gt;&#10; &lt;a href="#asyncawait" 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;上一节我们已经简单介绍了 async/await 的使用，接下来我们通过一个例子来加深对 async/await 的理解。如下是一个下载图片并展示在界面上的示例代码：&lt;/p&gt;</description></item><item><title>1.3 SwiftUI 中常见的异步 API</title><link>https://apolla.cc/posts/1.3-swiftui-%E4%B8%AD%E5%B8%B8%E8%A7%81%E7%9A%84%E5%BC%82%E6%AD%A5-api/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/1.3-swiftui-%E4%B8%AD%E5%B8%B8%E8%A7%81%E7%9A%84%E5%BC%82%E6%AD%A5-api/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;h1 class="heading-element" id="task"&gt;&lt;span&gt;.task&lt;/span&gt;&#10; &lt;a href="#task" 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;SwiftUI 刚发布时，View 只有两个最基础的生命周期方法：&lt;code&gt;.onAppear&lt;/code&gt; 和 &lt;code&gt;.onDisAppear&lt;/code&gt;，iOS 14 又新增了 &lt;code&gt;.onChange&lt;/code&gt; 这样的修饰器，可以监听值的变化。不过上面的几个 API 都是在主线程调用的，iOS 15 新增的 &lt;code&gt;.task&lt;/code&gt; 修饰器赋予了 View 快速开启异步任务的能力。&lt;/p&gt;</description></item><item><title>2.1 任务</title><link>https://apolla.cc/posts/2.1-%E4%BB%BB%E5%8A%A1/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/2.1-%E4%BB%BB%E5%8A%A1/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;h1 class="heading-element" id="任务的创建"&gt;&lt;span&gt;任务的创建&lt;/span&gt;&#10; &lt;a href="#%e4%bb%bb%e5%8a%a1%e7%9a%84%e5%88%9b%e5%bb%ba" 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;在前面的章节中，我们已经使用过 &lt;code&gt;Task&lt;/code&gt; 了，比如在同步环境 &lt;code&gt;viewDidLoad&lt;/code&gt; 方法中开启异步环境，或者使用 View 的 &lt;code&gt;.task&lt;/code&gt; 修饰器开启异步任务。还有 &lt;code&gt;async let&lt;/code&gt; 这样的语法糖，也会隐式地创建 task，方便我们写出简洁、安全的并发代码。&lt;/p&gt;</description></item><item><title>2.2 任务组</title><link>https://apolla.cc/posts/2.2-%E4%BB%BB%E5%8A%A1%E7%BB%84/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/2.2-%E4%BB%BB%E5%8A%A1%E7%BB%84/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;h1 class="heading-element" id="任务组的创建"&gt;&lt;span&gt;任务组的创建&lt;/span&gt;&#10; &lt;a href="#%e4%bb%bb%e5%8a%a1%e7%bb%84%e7%9a%84%e5%88%9b%e5%bb%ba" 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;&lt;code&gt;async let&lt;/code&gt; 和 &lt;code&gt;Task&lt;/code&gt; 能够满足我们大多数的并发需求，但在某些更复杂的需求场景下，它们力所不及。比如这样的需求：我们先发起一个网络请求，拉取所有要下载的书籍并展示在列表上。然后，我们要实现“下载全部”的功能。&lt;/p&gt;</description></item><item><title>2.3 小结</title><link>https://apolla.cc/posts/2.3-%E5%B0%8F%E7%BB%93/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/2.3-%E5%B0%8F%E7%BB%93/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;p&gt;前面的章节中，我们学习了 &lt;code&gt;async let&lt;/code&gt;、&lt;code&gt;Task&lt;/code&gt; 以及 &lt;code&gt;TaskGroup&lt;/code&gt; 的使用。它们都可以帮助我们写出高质量的并发代码，也各有千秋。&lt;/p&gt;&#10;&lt;p&gt;借助于 &lt;code&gt;async let&lt;/code&gt; 这个语法糖，我们能够在不直接接触 &lt;code&gt;Task&lt;/code&gt; 或 &lt;code&gt;TaskGroup&lt;/code&gt; 的层面上开启异步任务，获取异步返回结果，因此 &lt;code&gt;async let&lt;/code&gt; 又叫“并发绑定”，顾名思义，为某个变量绑定了并发任务的异步返回结果。&lt;/p&gt;</description></item><item><title>3.1 异步序列</title><link>https://apolla.cc/posts/3.1-%E5%BC%82%E6%AD%A5%E5%BA%8F%E5%88%97/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/3.1-%E5%BC%82%E6%AD%A5%E5%BA%8F%E5%88%97/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;h1 class="heading-element" id="asyncsequence-简介"&gt;&lt;span&gt;AsyncSequence 简介&lt;/span&gt;&#10; &lt;a href="#asyncsequence-%e7%ae%80%e4%bb%8b" 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;&lt;a href="https://developer.apple.com/documentation/swift/asyncsequence" target="_blank" rel="external nofollow noopener noreferrer"&gt;AsyncSequence&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;a href="https://developer.apple.com/documentation/swift/sequence" target="_blank" rel="external nofollow noopener noreferrer"&gt;Sequence&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;code&gt;for&lt;/code&gt;、&lt;code&gt;while&lt;/code&gt;、&lt;code&gt;repeat&lt;/code&gt; 循环访问子元素，也支持使用 &lt;code&gt;map&lt;/code&gt;、&lt;code&gt;filter&lt;/code&gt;、&lt;code&gt;reduce&lt;/code&gt; 等高阶函数，只不过这些操作都是异步的。&lt;/p&gt;</description></item><item><title>3.2 异步流</title><link>https://apolla.cc/posts/3.2-%E5%BC%82%E6%AD%A5%E6%B5%81/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/3.2-%E5%BC%82%E6%AD%A5%E6%B5%81/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;h1 class="heading-element" id="asyncstream-的使用"&gt;&lt;span&gt;AsyncStream 的使用&lt;/span&gt;&#10; &lt;a href="#asyncstream-%e7%9a%84%e4%bd%bf%e7%94%a8" 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;&lt;a href="https://developer.apple.com/documentation/swift/asyncstream" target="_blank" rel="external nofollow noopener noreferrer"&gt;AsyncStream&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;code&gt;AsyncSequence&lt;/code&gt; 协议的结构体，借助于它，我们无需手动实现异步迭代器，就可以方便地构建异步序列。相比 &lt;code&gt;AsyncSequence&lt;/code&gt; ，它是一个实现异步序列的轻量级方案。&lt;/p&gt;</description></item><item><title>4.1 actor 的使用</title><link>https://apolla.cc/posts/4.1-actor-%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.1-actor-%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="actor-并发模型"&gt;&lt;span&gt;Actor 并发模型&lt;/span&gt;&#10; &lt;a href="#actor-%e5%b9%b6%e5%8f%91%e6%a8%a1%e5%9e%8b" 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;&lt;img loading="lazy" src='https://apolla.cc/images/actor.png' alt="/images/actor.png"&gt;&lt;/p&gt;&#10;&lt;p&gt;actor 并发模型首次发表于 1973 年，是一个用于并发计算的数学模型。&lt;/p&gt;</description></item><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><item><title>4.3 Operators 使用手册（三）</title><link>https://apolla.cc/posts/4.3-operators-%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C%E4%B8%89/</link><pubDate>Fri, 19 Apr 2024 15:20:06 +0800</pubDate><guid>https://apolla.cc/posts/4.3-operators-%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C%E4%B8%89/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;h1 class="heading-element" id="republish"&gt;&lt;span&gt;Republish&lt;/span&gt;&#10; &lt;a href="#republish" 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;h2 class="heading-element" id="switchtolatest"&gt;&lt;span&gt;switchToLatest&lt;/span&gt;&#10; &lt;a href="#switchtolatest" 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;/h2&gt;&lt;p&gt;字面意思就是切换到最近的 publisher，这比较难那理解，我们结合代码来看。&lt;/p&gt;</description></item><item><title>1.1 Combine 概览</title><link>https://apolla.cc/posts/1.1-combine-%E6%A6%82%E8%A7%88/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/1.1-combine-%E6%A6%82%E8%A7%88/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;p&gt;WWDC 2019 上与声明式框架 SwiftUI 一同发布的，还有同等重要的响应式框架 Combine，它用于处理（异步）事件和数据流。随着 Concurrency 框架的发布和 SwiftUI 的不断完善，可能在实际开发中 Combine 直接露面的概率会越来越小。但它是 SwiftUI 简洁高效的基石，了解它有助于更好地理解和使用 SwiftUI。&lt;/p&gt;&#10;&lt;p&gt;Combine 框架包含三个核心概念：Publisher、Subscriber、Operator。&lt;/p&gt;</description></item><item><title>2.1 Publisher 的基本使用（一）</title><link>https://apolla.cc/posts/2.1-publisher-%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%E4%B8%80/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/2.1-publisher-%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%E4%B8%80/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;p&gt;在前面的章节中，实际上我们已经多次使用过 Publisher，只是我们不曾察觉。比如我们之前使用的 ObservedObject，它的定义如下：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;@propertyWrapper @frozen struct ObservedObject&amp;lt;ObjectType&amp;gt; where ObjectType : ObservableObject&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;其中的泛型 ObjectType 遵循 &lt;strong&gt;ObservableObject&lt;/strong&gt; 协议，该协议的定义中只有一个属性：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;// A publisher that emits before the object has changed.&#10;var objectWillChange: Self.ObjectWillChangePublisher&#10;&#10;// The type of publisher that emits before the object has changed.&#10;associatedtype ObjectWillChangePublisher : Publisher = ObservableObjectPublisher&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;其中的关联类型 ObjectWillChangePublisher 正是遵循 &lt;strong&gt;Publisher&lt;/strong&gt; 协议。也就是说，当我们使用 ObservedObject 时，系统会隐式地生成 objectWillChange 这样一个 Publisher，一旦遵循 ObservableObject 的 class 中标记为 @Published 的属性值发生变化，就会通过该 Publisher 告知相关的对象。&lt;/p&gt;</description></item><item><title>2.2 Publisher 的基本使用（二）</title><link>https://apolla.cc/posts/2.2-publisher-%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%E4%BA%8C/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/2.2-publisher-%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%E4%BA%8C/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;h1 class="heading-element" id="anypublisher"&gt;&lt;span&gt;AnyPublisher&lt;/span&gt;&#10; &lt;a href="#anypublisher" 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;前面视图部分的内容我们提到过，有些情况下， View 为了避免在传参或返回时类型不一致从而无法通过编译时，可以使用 AnyView 来作类型擦除，以此使得视图变得通用。&lt;/p&gt;</description></item><item><title>2.3 特殊的 Publisher：Subject</title><link>https://apolla.cc/posts/2.3-%E7%89%B9%E6%AE%8A%E7%9A%84-publishersubject/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/2.3-%E7%89%B9%E6%AE%8A%E7%9A%84-publishersubject/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;p&gt;Subject 协议继承自 Publisher 协议，遵循 Subject 协议的 Publisher 是一种特定类型的 Publisher，它有如下方法：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;/** Subject 协议方法 */&#10;&#10;/** 向订阅者发送数据 */&#10;// 发送指定值&#10;func send(Self.Output)&#10;// 发送空值（此时 Output 类型为 Void）&#10;func send()&#10;&#10;/** 向订阅者发送生命周期事件 */&#10;// 发送 subscription 实例&#10;func send(subscription: Subscription)&#10;&#10;// 发送 completion 信号&#10;func send(completion: Subscribers.Completion&amp;lt;Self.Failure&amp;gt;)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Subject 的特别之处在于，我们可以手动调用 send 方法向数据流注入新的值。&lt;/p&gt;</description></item><item><title>3.1 Subscriber 的详细介绍</title><link>https://apolla.cc/posts/3.1-subscriber-%E7%9A%84%E8%AF%A6%E7%BB%86%E4%BB%8B%E7%BB%8D/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/3.1-subscriber-%E7%9A%84%E8%AF%A6%E7%BB%86%E4%BB%8B%E7%BB%8D/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;h1 class="heading-element" id="订阅行为的详细过程"&gt;&lt;span&gt;订阅行为的详细过程&lt;/span&gt;&#10; &lt;a href="#%e8%ae%a2%e9%98%85%e8%a1%8c%e4%b8%ba%e7%9a%84%e8%af%a6%e7%bb%86%e8%bf%87%e7%a8%8b" 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;前面我们介绍过了，&lt;strong&gt;Subscriber&lt;/strong&gt; 是一个协议，和 Publisher 遥相呼应，前者接收数据（Input、Failure），后者发送数据（Output、Failure)，数据类型必须保持一致。&lt;/p&gt;</description></item><item><title>3.2 内建 Subscriber 的使用</title><link>https://apolla.cc/posts/3.2-%E5%86%85%E5%BB%BA-subscriber-%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/3.2-%E5%86%85%E5%BB%BA-subscriber-%E7%9A%84%E4%BD%BF%E7%94%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;p&gt;Combine 内建了两个 Subscriber：sink、assign，SwiftUI 框架中有一个内建的 Subscriber：onReceive。&lt;/p&gt;&#10;&lt;h1 class="heading-element" id="sink"&gt;&lt;span&gt;sink&lt;/span&gt;&#10; &lt;a href="#sink" 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;关于 sink，前面我们已经介绍过了。这里只做复习：它的作用是生成订阅者来接收发布者发送的数据，该订阅者在 receiveCompletion 闭包中返回事件结束的消息，在 receiveValue 闭包中返回接收到的数据值。&lt;/p&gt;</description></item><item><title>4.1 Operators 使用手册（一）</title><link>https://apolla.cc/posts/4.1-operators-%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C%E4%B8%80/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/4.1-operators-%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C%E4%B8%80/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;p&gt;我们可以在数据流的管道中，使用 Operators 对上游的数据进行各种操作，然后再发送给下游的订阅者，这就是 Operators 的作用。&lt;/p&gt;&#10;&lt;p&gt;Combine 提供了大量的 Operators 给我们使用，鉴于内容过多，笔者将其分为三个小节。&lt;/p&gt;&#10;&lt;p&gt;后续内容用了部分&lt;strong&gt;弹珠图&lt;/strong&gt;来加深理解，有兴趣的读者可以进一步了解：&lt;a href="https://rx-marbles-online.herokuapp.com/" target="_blank" rel="external nofollow noopener noreferrer"&gt;Marble Diagrams&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><item><title>4.2 Operators 使用手册（二）</title><link>https://apolla.cc/posts/4.2-operators-%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C%E4%BA%8C/</link><pubDate>Fri, 19 Apr 2024 15:20:05 +0800</pubDate><guid>https://apolla.cc/posts/4.2-operators-%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C%E4%BA%8C/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;h1 class="heading-element" id="mathematic"&gt;&lt;span&gt;Mathematic&lt;/span&gt;&#10; &lt;a href="#mathematic" 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;h2 class="heading-element" id="maxtrymax"&gt;&lt;span&gt;max、tryMax&lt;/span&gt;&#10; &lt;a href="#maxtrymax" 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;/h2&gt;&lt;p&gt;&lt;img loading="lazy" src='https://apolla.cc/images/max.png' alt="/images/max.png"&gt;&lt;/p&gt;</description></item><item><title>5 Swift 5.9 新特性</title><link>https://apolla.cc/posts/5-swift-5.9-%E6%96%B0%E7%89%B9%E6%80%A7/</link><pubDate>Fri, 19 Apr 2024 15:20:06 +0800</pubDate><guid>https://apolla.cc/posts/5-swift-5.9-%E6%96%B0%E7%89%B9%E6%80%A7/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;注：Swift 5.9 目前并未正式发布，本文会在正式发布后再次更新。&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;h1 class="heading-element" id="if-和-switch-表达式se-0380"&gt;&lt;span&gt;if 和 switch 表达式（&lt;a href="https://github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md" target="_blank" rel="external nofollow noopener noreferrer"&gt;SE-0380&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;/span&gt;&#10; &lt;a href="#if-%e5%92%8c-switch-%e8%a1%a8%e8%be%be%e5%bc%8fse-0380" 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;pre&gt;&lt;code&gt;let s1 = if Bool.random() { &amp;#34;YES&amp;#34; } else { &amp;#34;NO&amp;#34; }&#10;&#10;let s2 = switch Bool.random() {&#10;case true: &amp;#34;YES&amp;#34;&#10;case false: &amp;#34;NO&amp;#34;&#10;}&lt;/code&gt;&lt;/pre&gt;&lt;h1 class="heading-element" id="值和类型参数包se-0393"&gt;&lt;span&gt;值和类型参数包（&lt;a href="https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md" target="_blank" rel="external nofollow noopener noreferrer"&gt;SE-0393&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;/span&gt;&#10; &lt;a href="#%e5%80%bc%e5%92%8c%e7%b1%bb%e5%9e%8b%e5%8f%82%e6%95%b0%e5%8c%85se-0393" 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;值和类型参数，实现了对不同类型的值和类型的抽象化，这是在 Swift 中实现可变泛型的第一步。&lt;/p&gt;</description></item><item><title>4 Swift 5.8 新特性</title><link>https://apolla.cc/posts/4-swift-5.8-%E6%96%B0%E7%89%B9%E6%80%A7/</link><pubDate>Fri, 31 Mar 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/4-swift-5.8-%E6%96%B0%E7%89%B9%E6%80%A7/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="闭包内隐式调用-selfse-0365"&gt;&lt;span&gt;闭包内隐式调用 self（&lt;a href="https://github.com/apple/swift-evolution/blob/main/proposals/0365-implicit-self-weak-capture.md" target="_blank" rel="external nofollow noopener noreferrer"&gt;SE-0365&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;/span&gt;&#10; &lt;a href="#%e9%97%ad%e5%8c%85%e5%86%85%e9%9a%90%e5%bc%8f%e8%b0%83%e7%94%a8-selfse-0365" 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;pre&gt;&lt;code&gt;class Timer {&#10; var eventHandler: (() -&amp;gt; Void)?&#10; &#10; func start() {&#10; DispatchQueue.main.asyncAfter(deadline: .now() &amp;#43; 5) {&#10; self.eventHandler?()&#10; }&#10; }&#10;}&#10;&#10;class ViewController {&#10; let timer = Timer()&#10; &#10; init() {&#10; timer.eventHandler = { [weak self] in&#10; guard let self else { return }&#10; // 如果已使用 [weak self] 捕获了 self 并且解包&#10; // 则无需显式调用 self&#10; doSomething()&#10; }&#10; timer.start()&#10; }&#10; &#10; func doSomething() {&#10; print(&amp;#34;Doing something...&amp;#34;)&#10; }&#10;}&lt;/code&gt;&lt;/pre&gt;&lt;h1 class="heading-element" id="集合类型支持向下类型转换"&gt;&lt;span&gt;集合类型支持向下类型转换&lt;/span&gt;&#10; &lt;a href="#%e9%9b%86%e5%90%88%e7%b1%bb%e5%9e%8b%e6%94%af%e6%8c%81%e5%90%91%e4%b8%8b%e7%b1%bb%e5%9e%8b%e8%bd%ac%e6%8d%a2" 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;pre&gt;&lt;code&gt;class A {}&#10;class A1: A {}&#10;class A2: A {}&#10;&#10;func downcast(arr: [A]) {&#10; switch arr {&#10; case let a1 as [A1]:&#10; print(&amp;#34;arr is [A1]: \(a1)&amp;#34;)&#10; case let a2 as [A2]:&#10; print(&amp;#34;arr is [A2]: \(a2)&amp;#34;)&#10; default:&#10; print(&amp;#34;Unknown collection type&amp;#34;)&#10; }&#10;}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Swift 5.8 以前，以上的代码无法通过编译。需要这样写才可以：&lt;/p&gt;</description></item><item><title>3 Swift 中的 Result builders</title><link>https://apolla.cc/posts/3-swift-%E4%B8%AD%E7%9A%84-result-builders/</link><pubDate>Tue, 30 Aug 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3-swift-%E4%B8%AD%E7%9A%84-result-builders/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;在以往的命令式编程中，通常这样构建视图：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;let label = UILabel()&#10;label.frame = self.view.bounds&#10;self.view.addSubview(label)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;但 SwiftUI 采用的是声明式语法：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;VStack {&#10; Text(&amp;#34;1&amp;#34;)&#10;&#9;List {&#10; Text(&amp;#34;&amp;#34;)&#10; }&#10;}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;显而易见，SwiftUI 比 UIKit 要简洁地多，我们可以轻松地将不同的视图组合成复杂的界面。这得益于 Result builders（结果构造器），它使 SwiftUI 成为了特定领域语言（DSL）。&lt;/p&gt;</description></item><item><title>1 Swift 5.7 新特性</title><link>https://apolla.cc/posts/1-swift-5.7-%E6%96%B0%E7%89%B9%E6%80%A7/</link><pubDate>Fri, 15 Jul 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1-swift-5.7-%E6%96%B0%E7%89%B9%E6%80%A7/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="简化的可选绑定se-0345"&gt;&lt;span&gt;简化的可选绑定（&lt;a href="https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md" target="_blank" rel="external nofollow noopener noreferrer"&gt;SE-0345&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;/span&gt;&#10; &lt;a href="#%e7%ae%80%e5%8c%96%e7%9a%84%e5%8f%af%e9%80%89%e7%bb%91%e5%ae%9ase-0345" 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;对可选类型解包时无需显式绑定，写法更简洁：&lt;/p&gt;</description></item><item><title>2 Swift 中的不透明类型和存在类型</title><link>https://apolla.cc/posts/2-swift-%E4%B8%AD%E7%9A%84%E4%B8%8D%E9%80%8F%E6%98%8E%E7%B1%BB%E5%9E%8B%E5%92%8C%E5%AD%98%E5%9C%A8%E7%B1%BB%E5%9E%8B/</link><pubDate>Wed, 13 Jul 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2-swift-%E4%B8%AD%E7%9A%84%E4%B8%8D%E9%80%8F%E6%98%8E%E7%B1%BB%E5%9E%8B%E5%92%8C%E5%AD%98%E5%9C%A8%E7%B1%BB%E5%9E%8B/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="不透明类型some-关键字"&gt;&lt;span&gt;不透明类型、some 关键字&lt;/span&gt;&#10; &lt;a href="#%e4%b8%8d%e9%80%8f%e6%98%8e%e7%b1%bb%e5%9e%8bsome-%e5%85%b3%e9%94%ae%e5%ad%97" 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;&lt;code&gt;some&lt;/code&gt; 关键字由 Swift 5.1 引入，它用来修饰某个协议，使之成为&lt;strong&gt;不透明类型&lt;/strong&gt;。&lt;/p&gt;</description></item></channel></rss>