<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>9 搜索 on 编程那些事儿</title><link>https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/</link><description>Recent content in 9 搜索 on 编程那些事儿</description><generator>Hugo</generator><language>zh-cn</language><lastBuildDate>Sun, 13 Sep 2026 18:20:56 +0800</lastBuildDate><atom:link href="https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/index.xml" rel="self" type="application/rss+xml"/><item><title>9.1 为应用添加搜索界面</title><link>https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/9.1-AddingASearchInterfaceToYourApp/</link><pubDate>Sat, 12 Sep 2026 12:47:47 +0800</pubDate><guid>https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/9.1-AddingASearchInterfaceToYourApp/</guid><description>&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://developer.apple.com/documentation/swiftui/adding-a-search-interface-to-your-app"&gt;https://developer.apple.com/documentation/swiftui/adding-a-search-interface-to-your-app&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="91-为应用添加搜索界面"&gt;9.1 为应用添加搜索界面&lt;/h1&gt;
&lt;p&gt;提供一个界面，让人们可以在应用中搜索内容。&lt;/p&gt;
&lt;h2 id="Overview"&gt;概述&lt;/h2&gt;
&lt;p&gt;通过把某个 searchable 视图修饰符（例如 &lt;a href="https://developer.apple.com/documentation/swiftui/view/searchable(text:placement:prompt:)"&gt;searchable(text:placement:prompt:)&lt;/a&gt;）应用到 &lt;a href="https://developer.apple.com/documentation/swiftui/navigationsplitview"&gt;NavigationSplitView&lt;/a&gt; 或 &lt;a href="https://developer.apple.com/documentation/swiftui/navigationstack"&gt;NavigationStack&lt;/a&gt;，或者应用到它们内部的某个视图，就能为应用添加搜索界面。随后工具栏中会出现一个搜索框。搜索框的确切位置与外观取决于平台、你在代码中放置该修饰符的位置以及它的配置。&lt;/p&gt;
&lt;p&gt;
 
 
 
 
 
 
 
 
 
 
 &lt;img src="https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/images/Search-add-0-macOS@2x.png"
 alt="一个圆角宽矩形，左边是放大镜，右边是灰色的 Search 文本。" data-cur-dir="Swift/SwiftUI/appstructure/9-Search" data-rg="/images/Search-add-0-macOS@2x.png" data-rg1="images/Search-add-0-macOS@2x.png" data-rel="/prgms/images/Search-add-0-macOS@2x.png" data-c4my="/prgms"
 
 /&gt;
 
 
&lt;/p&gt;
&lt;p&gt;创建搜索框的 searchable 修饰符接收一个指向字符串的 &lt;a href="https://developer.apple.com/documentation/swiftui/binding"&gt;Binding&lt;/a&gt;，该字符串代表搜索框中的文本。你负责提供这个字符串的存储，以及（可选的）离散搜索令牌数组的存储，并用它们执行搜索。要了解如何管理搜索框的数据，参见&lt;a href="../9.2-PerformingASearchOperation/"&gt;执行搜索操作&lt;/a&gt;。&lt;/p&gt;</description></item><item><title>9.2 执行搜索操作</title><link>https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/9.2-PerformingASearchOperation/</link><pubDate>Sat, 12 Sep 2026 12:47:47 +0800</pubDate><guid>https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/9.2-PerformingASearchOperation/</guid><description>&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://developer.apple.com/documentation/swiftui/performing-a-search-operation"&gt;https://developer.apple.com/documentation/swiftui/performing-a-search-operation&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="92-执行搜索操作"&gt;9.2 执行搜索操作&lt;/h1&gt;
&lt;p&gt;根据你存储的搜索文本以及可选令牌更新搜索结果。&lt;/p&gt;
&lt;h2 id="overview"&gt;概述&lt;/h2&gt;
&lt;p&gt;要在应用的数据模型中执行搜索，先为查询文本创建存储，并用 searchable 视图修饰符呈现它。由于存储由你管理，你可以检测到它的变化并相应地更新搜索操作。随着人们输入而更新搜索结果，可以确保应用的搜索界面响应及时。&lt;/p&gt;</description></item><item><title>9.3 提供搜索词建议</title><link>https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/9.3-SuggestingSearchTerms/</link><pubDate>Sat, 12 Sep 2026 12:47:47 +0800</pubDate><guid>https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/9.3-SuggestingSearchTerms/</guid><description>&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://developer.apple.com/documentation/swiftui/suggesting-search-terms"&gt;https://developer.apple.com/documentation/swiftui/suggesting-search-terms&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="93-提供搜索词建议"&gt;9.3 提供搜索词建议&lt;/h1&gt;
&lt;p&gt;向在应用中搜索内容的人提供建议。&lt;/p&gt;
&lt;h2 id="overview"&gt;概述&lt;/h2&gt;
&lt;p&gt;你可以通过提供一组搜索建议视图，在搜索过程中建议查询文本。由于建议视图并不限于纯文本，你还必须提供每个建议视图所代表的搜索字符串。如果你的搜索界面包含令牌，你也可以为令牌提供建议。SwiftUI 会把建议显示在搜索框下方的列表中。&lt;/p&gt;</description></item><item><title>9.4 限定搜索操作的范围</title><link>https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/9.4-ScopingASearchOperation/</link><pubDate>Sat, 12 Sep 2026 12:47:47 +0800</pubDate><guid>https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/9.4-ScopingASearchOperation/</guid><description>&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://developer.apple.com/documentation/swiftui/scoping-a-search-operation"&gt;https://developer.apple.com/documentation/swiftui/scoping-a-search-operation&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="94-限定搜索操作的范围"&gt;9.4 限定搜索操作的范围&lt;/h1&gt;
&lt;p&gt;把搜索空间划分为几个宽泛的类别。&lt;/p&gt;
&lt;h2 id="overview"&gt;概述&lt;/h2&gt;
&lt;p&gt;如果你要搜索的数据可以分为几个类别，就可以定义不同的作用域，帮助人们缩小搜索范围。定义作用域之后，SwiftUI 会呈现一个选择器，让人们从中选择一个。随后你把这个当前选中的作用域，作为搜索操作的输入之一。&lt;/p&gt;</description></item><item><title>9.5 管理搜索界面的激活</title><link>https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/9.5-ManagingSearchInterfaceActivation/</link><pubDate>Sat, 12 Sep 2026 12:47:47 +0800</pubDate><guid>https://before80.github.io/prgms/Swift/SwiftUI/appstructure/9-Search/9.5-ManagingSearchInterfaceActivation/</guid><description>&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://developer.apple.com/documentation/swiftui/managing-search-interface-activation"&gt;https://developer.apple.com/documentation/swiftui/managing-search-interface-activation&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="95-管理搜索界面的激活"&gt;9.5 管理搜索界面的激活&lt;/h1&gt;
&lt;p&gt;以编程方式检测并关闭搜索框。&lt;/p&gt;
&lt;h2 id="overview"&gt;概述&lt;/h2&gt;
&lt;p&gt;人们通过轻点或点击来激活应用中的搜索框，之后就可以输入搜索词。在许多情况下，你的应用只需要对搜索文本值的相应变化做出反应——界面会通过你提供的绑定来更新这些值，如&lt;a href="../9.2-PerformingASearchOperation/"&gt;执行搜索操作&lt;/a&gt;所述。&lt;/p&gt;</description></item></channel></rss>