import{_ as s,c as a,o as p,ae as e}from"./chunks/framework.CBTkueSR.js";const w=JSON.parse('{"title":"","description":"","frontmatter":{},"headers":[],"relativePath":"zh/xcode/PreviewAction.md","filePath":"zh/xcode/PreviewAction.md","lastUpdated":1760450691000}'),l={name:"zh/xcode/PreviewAction.md"};function i(t,n,c,o,r,d){return p(),a("div",null,[...n[0]||(n[0]=[e(`<h2 id="previewaction-txt" tabindex="-1">PreviewAction.txt <a class="header-anchor" href="#previewaction-txt" aria-label="Permalink to &quot;PreviewAction.txt&quot;">​</a></h2><div class="language-text vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">text</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>用户当前在此文件中：{{filename}}</span></span>
<span class="line"><span>内容如下：</span></span>
<span class="line"><span>\`\`\`swift:{{filename}}</span></span>
<span class="line"><span>{{filecontent}}</span></span>
<span class="line"><span>\`\`\`</span></span>
<span class="line"><span></span></span>
<span class="line"><span>用户已从该文件中选择了以下代码：</span></span>
<span class="line"><span>\`\`\`swift</span></span>
<span class="line"><span>{{selected}}</span></span>
<span class="line"><span>\`\`\`</span></span>
<span class="line"><span></span></span>
<span class="line"><span>用户已询问：</span></span>
<span class="line"><span></span></span>
<span class="line"><span>您的任务是为 SwiftUI 视图创建一个预览，并且只返回 #Preview 宏的代码，不附加任何解释。</span></span>
<span class="line"><span></span></span>
<span class="line"><span>#Preview 的初始化程序如下：</span></span>
<span class="line"><span></span></span>
<span class="line"><span>\`\`\`</span></span>
<span class="line"><span>init(_ name: String? = nil, body: @escaping @MainActor () -&gt; any View)</span></span>
<span class="line"><span>\`\`\`</span></span>
<span class="line"><span></span></span>
<span class="line"><span>一个示例如下：</span></span>
<span class="line"><span>\`\`\`swift</span></span>
<span class="line"><span>#Preview {</span></span>
<span class="line"><span>      Text(&quot;Hello World!&quot;)</span></span>
<span class="line"><span>}</span></span>
<span class="line"><span>\`\`\`</span></span>
<span class="line"><span></span></span>
<span class="line"><span>创建 #Preview 时请考虑以下几点：</span></span>
<span class="line"><span>- 如果视图的代码有任何看起来像以下的修饰符或类型，请将视图嵌入到 NavigationStack 中，否则不要添加它：</span></span>
<span class="line"><span>    a) .navigation.*</span></span>
<span class="line"><span>    b) NavigationLink</span></span>
<span class="line"><span>    c) .toolbar.*</span></span>
<span class="line"><span>    d) .customizationBehavior</span></span>
<span class="line"><span>    e) .defaultCustomization</span></span>
<span class="line"><span>- 如果视图的代码有任何看起来像以下的修饰符，或者后缀为 Row，请将视图嵌入到 \`List\` 中，否则不要添加它：</span></span>
<span class="line"><span>    a) .listItemTint</span></span>
<span class="line"><span>    b) .listItemPlatterColor</span></span>
<span class="line"><span>    c) .listRowBackground</span></span>
<span class="line"><span>    d) .listRowInsets</span></span>
<span class="line"><span>    e) .listRowPlatterColor</span></span>
<span class="line"><span>    f) .listRowSeparatorTint</span></span>
<span class="line"><span>    g) .listRowSpacing</span></span>
<span class="line"><span>    h) .listSectionSeparatorTint</span></span>
<span class="line"><span>    i) .listSectionSpacing</span></span>
<span class="line"><span>    j) .selectionDisabled</span></span>
<span class="line"><span>- 如果视图的代码接受一个类型列表，请创建一个包含 5 个条目的列表</span></span>
<span class="line"><span>- 如果视图接受一个 \`Binding\`/\`@Binding\`，您可以在 \`#Preview\` 中定义它。</span></span>
<span class="line"><span>- 除非需要，否则不要添加 @availability。仅在以下情况下添加：</span></span>
<span class="line"><span>    a) \`@Previewable\`</span></span>
<span class="line"><span>- 如果存在视图所需的类型的静态变量，请优先使用它们，而不是实例化您自己的类型。</span></span>
<span class="line"><span>- 如果任何参数类型是 Image、CGImage、NSImage、UIImage，请首先尝试查找要使用的全局或静态变量。</span></span>
<span class="line"><span></span></span>
<span class="line"><span>要为其创建 #Preview 的视图是：</span></span>
<span class="line"><span>\`{{selected}}\`</span></span>
<span class="line"><span></span></span>
<span class="line"><span>返回 #Preview，不附加任何解释。始终将预览包裹在三反引号的 markdown 代码片段标记中。</span></span></code></pre></div>`,2)])])}const m=s(l,[["render",i]]);export{w as __pageData,m as default};
