|
Hey everyone! So I am working on the 3rd challenge for Day 47 and I can't get any data to show from the ActivityClass into the DetailView. When I try to reach back to the class, all I can pull is properties about the array. I can't actually get into the Activity struct and pull specific properties. How can I rectify this conundrum? I had left the code in a buildable state, hence why I have ""(activity.activities.count)"" in my DetailView. And it shows that I can only access the array, not the struct.
|
|
Your list is showing individual activities. Each activity (the struct) has 3 properties, 2 of which I presume you want to show in the detail view. Your DetailView should take Activity and not ActivityClass.
And you change your NavigationLink to this:
This should work. |
|
Thank you so much. I was thinking that since the Class already reaches back to the Activity Struct, I thought that was the way to pass it onto the DetailView. But now I understand that I was calling for the array of activities instead of the individual object itself. |
|
An additional clarification: Your class is publishing any changes to the array. It is set as an observed object in your main view. This object (var activityClass) is what you are using for your data. Not the original class (the model). Which is why you use it in your ForEach. Passing data between screens or views can sometimes be tricky. So always make sure you are using the right type. Don't worry about how to get it at first. Just what it needs to be. So in your DetailView, you already knew you needed to display the details of an Activity. Start there, then think about how to pass that to your DetailView. I like to approach it like this: What do I want to show? then What data do I need for that? then How do I get it to where I want it to be? Glad I could help. Keep up the good work 👍 |
|
When I pass an UPDATE: found solution here https://www.hackingwithswift.com/forums/100-days-of-swiftui/problem-with-passing-data-with-navigationlink-challenge-day-47/136/153 |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
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.