How do I use an environment variable in SwiftUI?
Asked on 02/03/2025
1 search
To use an environment variable in SwiftUI, you can take advantage of the new entry macro introduced in the latest updates. This macro simplifies the process of working with environment values. Instead of writing a full conformance to EnvironmentKey
and an extension on EnvironmentValues
, you can now define a simple property using the entry macro. This makes it easier to manage environment values in your SwiftUI applications.
For more detailed information, you can refer to the session What’s new in SwiftUI (13:25).

Create custom visual effects with SwiftUI
Discover how to create stunning visual effects in SwiftUI. Learn to build unique scroll effects, rich color treatments, and custom transitions. We’ll also explore advanced graphic effects using Metal shaders and custom text rendering.

What’s new in SwiftUI
Learn how you can use SwiftUI to build great apps for any Apple platform. Explore a fresh new look and feel for tabs and documents on iPadOS. Improve your window management with new windowing APIs, and gain more control over immersive spaces and volumes in your visionOS apps. We’ll also take you through other exciting refinements that help you make expressive charts, customize and layout text, and so much more.

Get started with HealthKit in visionOS
Discover how to use HealthKit to create experiences that take full advantage of the spatial canvas. Learn the capabilities of HealthKit on the platform, find out how to bring an existing iPadOS app to visionOS, and explore the special considerations governing HealthKit during a Guest User session. You’ll also learn ways to use SwiftUI, Swift Charts, and Swift concurrency to craft innovative experiences with HealthKit.