|
I don't know if flow of data are the correct words but i try to explain. one of my biggest problem learning to program is keeping with the var the strucs and so on. At the moment i am in moonshot (proyect 8), and i am havin a hard time keeping with what is what... The init() in the MissionView i was thinking what is $0.id == member.name ???
and while thinking this i start thinkin about how every thing is create, strore and load.
This is declare in ContentView, this means that de json is store in let mission? or is it store in the [Mission] array struct?? Once is store then in MissionView we declare
this is taking the data from the Mission struc?? I don't know if my aproach is correct. Hope a ihave explain what my doubt is. Thank you |
|
I haven't actually looked at this particular code myself, but with regards to the first question:
the
So it looks like the astronaut id field is a name. |
|
Thank you but i do not mean that. first we create the struct
then we asing to a porperty in the ContentView
but if i want to use that data in other view we use (MissionView)
what i do not understan is that in the ContentView we press the first mission that pases the data from the struct Mission??to the MissionView? |
|
The JSON is decoded into an array of
|
|
In ContentView, there are two properties, both are arrays, named missions and astronauts. The data in these properties is passed in from the decode method on Bundle.
The missions array is passed into List in the NavigationView. List consumes the items in the array one at a time, and each item renders a row in the list. So, a struct that contains all the properties of a single mission is known to each row of the List.
// NOTE HOW missions inside the parenthesis is the array of Mission, and the mission between the "{" brace and the "in" keyword is a local parameter that contains a single mission.
When a list row is tapped, the NavigationLink is called with two parameters, a single instance of type Mission, and an array of type Astronauts. MissionView is initialized with the two parameters copied in in from ContentView, mission, which is a single mission, and astronauts, which is now an array of CrewMember. These values are created in memory by the init inside MissionView.
That is how the data gets from the json files into the MissionView view. Note it gets copied from one scope to another several times, and the astronauts array changes type when passed from ContentView. Bob |
|
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
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.