UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Moonshot

Forums > 100 Days of SwiftUI

Hi folks, I had a really tough time this round. I usually work ahead and try to solve what comes up by myself and then look at Paul's approach. I had my biggest problems with merging the data from the missions and the astronauts. Then when I saw the solution, I felt like an idiot. After that I thought maybe I can show the missions in the astronaut detail view. But I didn't manage to search the missions and the crew for the astronaut's name. I think I should stop programming if I can't even do something that simple. Does any body else feels similiar?

2      

I feel your pain. I'm struggling through the Moonshot App myself. It's the toughest one to date for me. There's a lot of information in the videos for these days. It's like drinking out of a fire hose. Plus it seems like for everything one thing I learn, I forget something else I already learned. Dictionaries are not something I've worked with before and they've made this app particularly difficult for me. I had to stop and play around with an Xcode playground to work through them using a small portion of the data from the JSON files in the Moonshot App. I've had feelings of giving up, but at least for now I plan on trying to get through it. I got stuck on the iExpense one and got through that one.

If you get stuck on something specific, ask for help here. Many people here have helped me out. Try to be as specific as possible and include code examples.

See my Moonshot App frustration post: https://www.hackingwithswift.com/forums/100-days-of-swiftui/day-41-completed-not-really/12298

Also, this one: https://www.hackingwithswift.com/forums/100-days-of-swiftui/day-41-moonshot-app-confused-by-code/12327

Additonally, I've found the Day 0 video to be encouraging: https://www.hackingwithswift.com/100/swiftui/0

3      

4      

Thanks for your responses. Curiosly I feel better now, since I know you guys struggle too. I digged into that topic but couldn't find any other solution. My problem was, to map/filter etc. an array and then the nested array.

2      

Maybe a different example might help cement your knowledge?

Think about a deck of cards. All the face cards represent astronauts. Maybe your user asks to see all the astronauts who flew on the "Diamonds" mission.

What steps would you take to find the Jack, Queen, and King of diamonds in the deck of cards?

You might flip through each card, one at a time, and pull out all the diamonds. Then you might flip through the 13 diamond cards looking only for the face cards. This is how you might do it by hand.

But what @twostraws wanted to teach you is the .filter and .map commands for an array.
.filter is the array method for flipping through a deck of cards.

// Paste into Playgrounds

let deckOfCards =
    [("♥️", value:"👸🏾"), ("♦️", value:"3"), ("♠️", value:"👸🏾"), ("♦️", value:"5"),
     ("♦️", value:"🃋"), ("♦️", value:"👸🏾"), ("♦️", value:"🤴🏽")
]

// Flip through the deck of cards. First find queens, the find the diamond.
var allQueens       = deckOfCards.filter { $0.value == "👸🏾" }  // find all the queens in the deck.
var queenOfDiamonds = allQueens.filter { $0.0 == "♦️" } // find the queen of diamonds card.

// Note that both of these are the same type as deckOfCards. Both are arrays of tuples.
allQueens        // shows three cards, queen of diamonds, hearts, and spades
queenOfDiamonds  // array of just one card, the queen of diamonds

// .map() transforms the array of tuples into an array of Strings
let queenOfDiamond_card = queenOfDiamonds.map { $0.value + " " + $0.0 }
queenOfDiamond_card  // This is a [String]. .map changed the tuple to a string array

This is what you did with the array of all astronauts. First you found just the three astronauts for a single mission. But you needed more than just the plain astronaut data. You also needed his ROLE within the mission. So you used the .map() feature to transform a single Astronaut object into a Crew object. All three Crew objects form a new array in your Mission object, namely

let crew = [Crew] // an array of Crew members.

3      

Hacking with Swift is sponsored by Essential Developer

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.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

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.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.