<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>3 数据与存储 on 编程那些事儿</title><link>https://before80.github.io/prgms/Swift/SwiftUI/datastorage/</link><description>Recent content in 3 数据与存储 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/datastorage/index.xml" rel="self" type="application/rss+xml"/><item><title>2 环境值</title><link>https://before80.github.io/prgms/Swift/SwiftUI/datastorage/2-EnvironmentValues/</link><pubDate>Sat, 12 Sep 2026 12:47:47 +0800</pubDate><guid>https://before80.github.io/prgms/Swift/SwiftUI/datastorage/2-EnvironmentValues/</guid><description>&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://developer.apple.com/documentation/swiftui/environment-values"&gt;https://developer.apple.com/documentation/swiftui/environment-values&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="2-环境值"&gt;2 环境值&lt;/h1&gt;
&lt;p&gt;使用环境在整个视图层级中共享数据。&lt;/p&gt;
&lt;h2 id="Overview"&gt;概述&lt;/h2&gt;
&lt;p&gt;SwiftUI 中的视图可以响应它们通过 &lt;a href="https://developer.apple.com/documentation/swiftui/environment"&gt;Environment&lt;/a&gt; 属性包装器从环境中读取的配置信息。&lt;/p&gt;
&lt;p&gt;
 
 
 
 
 
 
 
 
 
 
 &lt;img src="https://before80.github.io/prgms/Swift/SwiftUI/datastorage/images/environment-values-hero@2x.png"
 alt="" data-cur-dir="Swift/SwiftUI/datastorage" data-rg="/images/environment-values-hero@2x.png" data-rg1="images/environment-values-hero@2x.png" data-rel="/prgms/images/environment-values-hero@2x.png" data-c4my="/prgms"
 
 /&gt;
 
 
&lt;/p&gt;
&lt;p&gt;视图从其容器视图继承环境，但可以被 &lt;a href="https://developer.apple.com/documentation/swiftui/view/environment(_:_:)"&gt;environment(&lt;em&gt;:&lt;/em&gt;:)&lt;/a&gt; 视图修饰符显式改变，也可以被众多作用于环境值的修饰符隐式改变。因此，你可以通过修改某个视图组容器的环境，来配置整个视图层级。&lt;/p&gt;</description></item><item><title>3 偏好设置</title><link>https://before80.github.io/prgms/Swift/SwiftUI/datastorage/3-Preferences/</link><pubDate>Sat, 12 Sep 2026 12:47:47 +0800</pubDate><guid>https://before80.github.io/prgms/Swift/SwiftUI/datastorage/3-Preferences/</guid><description>&lt;blockquote&gt;
&lt;p&gt;原文链接: &lt;a href="https://developer.apple.com/documentation/swiftui/preferences"&gt;https://developer.apple.com/documentation/swiftui/preferences&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="3-偏好设置"&gt;3 偏好设置&lt;/h1&gt;
&lt;p&gt;把配置偏好从视图传递给容纳它们的容器视图。&lt;/p&gt;
&lt;h2 id="Overview"&gt;概述&lt;/h2&gt;
&lt;p&gt;环境用于配置某个视图的子视图，而偏好设置则用于把配置信息从子视图向上发送给容器。不过，与从一个容器向下流向众多子视图的配置信息不同，单个容器需要协调从众多子视图向上流动的、可能相互冲突的偏好设置。&lt;/p&gt;</description></item></channel></rss>