|
I have a project with multiple views. Each view is in its own file. When I create my navigation link in ContentView() I can't get the parameters correct for calling the next view. I have been spending 4 days trying to figure this out by watching videos, reading and researching to no avail. I created each view and it works when display its preview, but when I moved the regions list to the ContentView() I can't get it to work: Thanks for any help. Here is my code: ContentView file
My landmarkData is contained in a seperate file:
my regions variable is in a seperate file:
My RegionView that is to be called after a region is selected is in a seperate file:
|
|
The error I am getting for line:
is Cannot convert value of type 'Landmark.Type' to expected argument type 'Landmark' |
|
So the idea seems to be that you have a list of regions and each region has a list of landmarks within it. In your You should set up your
So each Then your
And your
|
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
One thing that can help is how you name things. So, for instance, a |
|
@roosterboy, Thanks for your reply. I was finally able to get my ContentView() working after I changed this line:
to
I do plan on changing my Region struct like you said, but hand't gotten their yet. I wanted to make sure that what I had so far was working. In fact, It will be a bit more complicated than that. Each Region will have a choice of 5 different lists of landmarks, for example, POI, Dining, Museums, Castles, Churches. After each list is displayed, then you can get to choose a specific item and it will display the detail info about that item, and a choice to view the location on a map. Most of this is working. Still have to curate all of my images and info about each location. Yes you are right, naming can get a little confusing. Again, thanks for the help. |
|
I managed to get my Region struct changed with a variable poi: [Landmark] inside of it. When I call my RegionList View to display a list of POI's for that region, I am having a hard time figuring how to pass the info on to the next view:
I get the following errors:
Get's this error: Cannot convert value of type 'Region' to expected argument type 'Range<Int>' And
Get's these errors: Unnamed argument #2 must precede argument 'destination' alue of type 'Int' has no member 'poi' This is based on using the struct:
|
|
Right, because Instead, you would need to loop through the
(Although the argument for |
|
You are correct in that the naming is an issue. Working on fixing that. I can get a list of my
At the bottom of my
Do I need to change the |
|
What I would do is in your
|
|
In my RegionView() I originally had a NavigationLink() for each button seperately. I changed it to what you showd, and it makes that part a lot simpler with less code. However, I can't get past the error: Cannot convert value of type '[Landmark]' to expected argument type 'Landmark' for
In my RegionalList() View I put a variable:
I tried using a |
|
Since a
|
|
Ok. I really appreciate your help with this. Everything is working perfectly now. The last part Again, thanks for your help. I owe you a beer! |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
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.