|
Working on the Milestone project for day 78 with MapKit. How would you create a DetailView of a location on a map where each location from a list of populted locations has its own view? Calling I'm having trouble finding out where in the code I should initiate the mapRegion: in the ViewModel or in the DetailView? Recommendations much appreciated. See an example of DetailView and ViewModel: DetailView
ViewModel
Another option I could think of is changing DetailView to the following and update MapRegion based on the input coordinates in the Location struct:
|
|
You can either update the Map with a Button or you do it onAppear. Bear in mind onAppear is only called once when the view first appears. If you choose to use a ViewModel put the code for the loadMap in the viewModel and call it from there. This is personal preference and not a general rule. For a simple example like that one could choose not to use a ViewModel at all. But it's nothing wrong with it. |
|
I might have set up my project quite a bit different from the way you did, but I'm not sure how different they are from how much code you have shared here. They might be similar enough for this to be helpful... But I added a property to my
So, I am only using the Then, when you tap on one of your items in your list, it would take you to the I also have a
For one thing, I didn't initialize You really only set the For another thing, I just made my Also, I have a Sorry if this doesn't exactly answer your question, or if I showed you more of my code than you wanted. But I didn't exactly know how to answer this in any other way. |
|
@Fly0strich Thank you very much for taking me through your approach! I've been trying to implement the version of using As such I went back to my original approach and using a
|
|
I would need to see the code where this happens. Basically, it says your closure returned a value of type MKCoordinateRegion but was supposed to return nothing (aka Void). |
|
This method is returning a
|
|
Thank you all so much! (Learning so much from my errors here)
Updating the map view seemed so simple, referring to the
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.