Ryan Nee
1 min readAug 4, 2020

--

Super helpful, thanks! I'm new at this and your description was incredibly clear compared to anything else I have been able to find.

Very specific question: I have a map (e.g. MapView) with @State variable to hold the map's region, with a default set to London. The map's region is tied to that State variable with a binding so that as a person moves the map around, the State updates with the region currently in view. This seems in-line with your description of how State should be used in modest ways within a struct — so far, so good.

Now, imagine I have a view about different cities (CityView) populated by my data model, and I want to link to MapView via a NavigationLink or a Button to show a map of any given city. Would I want to create an @EnvironmentObject to hold the map's current region since the MapView and CityView aren't an exact parent/child relationship? Or would I want to use @ObservedObject because I want to pass data from the CityView to the MapView? Or are both of these routes wrong or unnecessary?

Ultimately, I want people to be able to navigate:

1. To the MapView directly (with its default region of London)

2. Access it from a CityView, somehow updating the MapView's @State with that city's region data

Forgive me if this is a totally dumb or obvious question, but this is the example I had in mind while reading your article. Thanks!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Ryan Nee
Ryan Nee

Written by Ryan Nee

I’m an avid traveler hellbent on visiting more than 100 countries before I die. Nomadic since 2018. Designing things for the internet since 1997.

Responses (1)

Write a response