Defining Custom Environment Keys in SwiftUI

When implementing apps using SwiftUI, we often need to access a view’s environment and read values from it. It’s easy to give environment a picture; think of it as a memory pool containing global values, shared and accessible all the way down to the view hierarchy.

SwiftUI framework sets several values to the environment by default. We can get them by declaring properties marked with the…

--

--

--

An iOS & macOS app maker writing code in Swift. Author of countless programming tutorials. Content creator. https://serialcoder.dev

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gabriel Theodoropoulos

Gabriel Theodoropoulos

An iOS & macOS app maker writing code in Swift. Author of countless programming tutorials. Content creator. https://serialcoder.dev

More from Medium

Displaying Borders in SwiftUI

Managing Data in SwiftUI

How to programmatically manage FocusState for dynamically created TextFields and TextEditors in…

Send data with navigation from View controller to SwiftUI view