|
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:
Thank you! |
|
Question 2: ForEach parameterA new programmer asks:
I like to think of 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 Raw Materials
In the Moonshot application, when you tap a mission Clarify IntentI 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 InitializerNew 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? Another attemptBut, 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 RoleWhat 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 Initializer SignatureReading 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 Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!
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.