I have the following view in my first SwuiftUI project:
import SwiftUI
struct RosaView: View {
@State var rosa: [Rosa] = Rosa.testRosa()
@State private var apriNuovoGiocatore = false
@State var stagione: String = "2023/2024"
var rosaFiltrata: [Rosa] {
Rosa.testRosa().filter {
$0.stagione == stagione
}
}
@State private var selezioneGiocatore: Rosa.ID? = nil
@State private var ordine = [KeyPathComparator(\Rosa.ruoloGiocatore)]
var body: some View {
VStack(alignment: .leading) {
Text("Stagione: \(stagione)")
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
.font(.headline)
.foregroundColor(/*@START_MENU_TOKEN@*/.blue/*@END_MENU_TOKEN@*/)
.padding()
Table(rosaFiltrata, selection: $selezioneGiocatore, sortOrder: $ordine) {
TableColumn(Text("Nome").foregroundStyle(.blue), value: \.nomeGiocatore)
TableColumn(Text("Cognome").foregroundStyle(.blue), value: \.cognomeGiocatore)
TableColumn(Text("Ruolo").foregroundStyle(.blue), value: \.ruoloGiocatore)
TableColumn(Text("Data di nascita").foregroundStyle(.blue), value: \.nascitaGiocatore)
TableColumn(Text("Età").foregroundStyle(.blue)) {
Rosa in
Text("\(Rosa.etàGiocatore)")
}
}
}
.frame(width: 900, height: 400)
.toolbar {
Button {
apriNuovoGiocatore = true
} label: {
Image(systemName: "person.badge.plus")
.foregroundColor(/*@START_MENU_TOKEN@*/.blue/*@END_MENU_TOKEN@*/)
}
.sheet(isPresented: $apriNuovoGiocatore, content: {
nuovoGiocatore()
})
}
.navigationTitle("Rosa")
}
}
struct nuovoGiocatore: View {
@Environment(\.dismiss) var dismiss
@State var nomeNuovoGiocatore: String
@State var cognomeNuovoGiocatore: String
@State var nascitaNuovoGiocatore: String
@State var ruoloNuovoGiocatore: String
@State var etàNuovoGiocatore: Int
var body: some View {
NavigationStack {
Form {
TextField("Nome:", text: $nomeNuovoGiocatore)
TextField("Cognome:", text: $cognomeNuovoGiocatore)
}
.navigationTitle("Nuovo giocatore")
.toolbar {
Button("Cancel") {
dismiss()
}
Button("Aggiungi giocatore") {
let nuovoGiocatore = Rosa(stagione: "2023/2024", nomeGiocatore: nomeNuovoGiocatore, cognomeGiocatore: cognomeNuovoGiocatore, nascitaGiocatore: nascitaNuovoGiocatore, etàGiocatore: etàNuovoGiocatore, ruoloGiocatore: ruoloNuovoGiocatore)
Rosa.testRosa().append(nuovoGiocatore)
dismiss()
}
}
}
}
}
#Preview {
RosaView()
}
I'm getting two strange errors. The first one is "Missing arguments for parameters 'nomeNuovoGiocatore', 'cognomeNuovoGiocatore', 'nascitaNuovoGiocatore', 'ruoloNuovoGiocatore', 'etàNuovoGiocatore' in call" when I'm calling nuovoGiocatore in sheet. The second one is in the view nuovoGiocatore and it says "Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs)"
What am I doing wrong???
Thanks in advance for your support, A.