WWDC22 SALE: Save 50% on all my Swift books and bundles! >>


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?


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



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.


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.


Hacking with Swift is sponsored by Emerge

SPONSORED Optimize your app’s startup time, binary size, and overall performance using Emerge’s advanced app optimization and monitoring tools. Reliably measure app size, speed up your app's startup time with Emerge's Launch Booster, and much more. Emerge is actively used by many of the top mobile development teams in the world.

Find out more

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

Reply to this topic…

You need to create an account or log in to reply.

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.