Returns
AnEnvironmentValues object with the following fields:
The current appearance mode.
The display pixel density (e.g. 2.0 for Retina displays).
The user’s preferred text size setting. See DynamicTypeSize.
The current locale identifier (e.g.
"en_US").Text layout direction.
Screen dimensions in points.
The current platform (e.g.
"iOS", "web", "android").Opens a URL using the platform’s default handler.
.environment() modifier are also available as additional properties on the returned object.
Usage
Adapt to color scheme
Responsive layout
Read custom environment values
Open a URL
Notes
useEnvironmentmust be called inside a componentbodyfunction, not at the top level.- Custom values are set via the
.environment()modifier on a parent component, e.g..environment("accentColor", "purple"). - The
screendimensions are in logical points, not physical pixels.
See Also
- OpenURLAction — custom URL handling