I'm reviewing Moonshot as part of 100 days of SwiftUI and have a bit of trouble connecting the dots on a few things. I'm hoping someone can explain these few things to me:
Question 1: In ContentView, not fully understanding how we are defining missions and astronaut, referring this code:
Question 2: In ContentView, why are we passing in mission: mission, and not missions: missions? Referring this code:
Question 3: How is it being decided which objects to bring in and what to pass in? I think majority of my questions are me trying to understand how missions and astronaut are being passed in, since in various parts of the code in this project, they have slightly different names/ways they are being passed in?
Question 4: Can someone explain the custom initializer in MissionView, referring to this code:
Question 2: ForEach parameter
A new programmer asks:
So, ask yourself: In the code snip above what is the
It appears you're trying to build several
Now that you understand that the
In the Moonshot application, when you tap a mission
I think it confuses new developers when the parameter labels match the incoming variable labels. I am often overruled in this opinion. But here's a great example of how this can be confusing.
The MissionView view needs a single mission, and an array of astronauts. The programmer used the same name for the paramater and variable.
This is more verbose, but maybe we can agree this is somewhat more understandable?
Question 4: Custom View Initializer
New Swift programmer also asks:
I'm not sure how I can top @twoStraws explanation here:
His explanation is laid out in detail. Perhaps we can help, if you point out sections of his explanations that you don't grasp?
But, I'll give it a try.
Imagine I handed you a fact sheet for Mission X and asked you to build the detail view with Logo, Description, Mission Dates, etc. But I also told you the crew were potter, grainger, and lovegood. In the data I give you, I ony tell you that lovegood was the commander, the other two were redshirt scientists.
I ask you to display each crewmember's photo, and short biography.
You also have a separate list of all the astronauts: ginny weasley, harry potter, ron weasley, draco malfoy, neville longbottom, etc. This list has their photos, biographies, and favorite spells.
Match Astronaut to the Mission Role
What you'll end up doing is looking at a mission (in this case Mission X) and you'll see that the mission commander was lovegood. Next, you'll look throught the entire list of astronauts until you find a match and you'll copy lovegood's data into the commander crew slot of your mission.
In short, this is what the initializer above is doing.
The initializer is looking at the name lovegood in the mission data. Then it looks (maps) through the list of astronauts for a match. When it finds a match, it copies that astronaut's information, AND the role that astronaut had in the mission to a NEW object called
Reading Signatures is a skill all SwiftUI developers need to build.
This initializer tells you that to build a single
This dictionary works like a Websters dictionary. You use the key word in a dictionary to find its definition, yes? If you look up the word cromulent, you won't find the definition of embiggen.
In the astronaut dictionary, if you need a biography for astronaut Draco Malfoy, you look him up using the (
SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.