TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

day 41 doubt

Forums > 100 Days of SwiftUI

here is the code

    init(mission: Mission, astronauts: [String: Astronaut]) {
        self.mission = mission

        self.crew = mission.crew.map { member in
            if let astronaut = astronauts[member.name] { //this line
                return CrewMember(role: member.role, astronaut: astronaut)
            } else {
                fatalError("Missing \(member.name)")
            }
        }
    }

whats astronaut and astronauts here?

2      

You see, on one side we have missions that know crew member “armstrong” had the role “Commander”, but has no idea who “armstrong” is, and on the other side we have “Neil A. Armstrong” and a description of him, but no concept that he was the commander on Apollo 11.This is the problem we need to address as stated by Paul, so we already have an Astronaut struct

struct Astronaut: Codable, Identifiable {
    let id: String
    let name: String
    let description: String
}

if let astronaut = astronauts[member.name] if there was an a astronaut in the astronauts json file which we define as [String: Astronaut] here the String is the name of astronaut also acts as key of dictionary, in the mission.json if we get the name of astronaut and it is also in astronaut.json then fetch it as key and pass value to CrewMember , to be used later...

This is an attempt to find some commom field as in database, to connect both tables together , here this is the name of astronaut ...if let astronaut is just checking if we can get a value from astronauts[member.name], as member.name will act as key , if so give me CrewMember else throw an error

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.