我无法解决本教程的第三个挑战:https://www.hackingwithswift.com/books/ios-swiftui/moonshot-wrap-up
我用错误的相同任务名称创建了3行,我需要在下面用3名工作人员创建一行
这是我的代码:
@State private var isDate = true
struct newCrews : Identifiable {
let id = UUID()
let name : Astronaut
let date : String?
let mission : String
}
var crwes : [newCrews]
init(missions:[Mission],astronauts:[Astronaut]) {
self.missions = missions
var matches = [newCrews]()
self.astronaut = astronauts
for mem in missions {
for meme in mem.crew {
for astra in astronauts {
if meme.name == astra.id {
matches.append(newCrews(name: astra, date: mem.formattedLaunchDate, mission: mem.displayName))
}
}
}
}
self.crwes = matches
}
var body: some View {
NavigationView {
List(crwes) { mission in
NavigationLink(destination: MissionView(mission: mission.mission, astronauts:
self.astronauts)) {
Image(mission.mission.image)
.resizable()
.scaledToFit()
.frame(width: 44, height: 44)
VStack(alignment: .leading) {
Text(mission.mission.displayName)
.font(.headline)
if self.isDate == true {
Text(mission.mission.formattedLaunchDate)
}else{
Text(mission.name.name)
}
}
}
}
.navigationBarItems(trailing: Button(action: {
self.isDate.toggle()
}, label: {
Text("change")
}))
.navigationBarTitle("Moonshot")
}
}