I created a list where you can add and edit names. Now I want to generate a random name (on my second page / view). Could someone help me?
File.swift:
class NameStore : ObservableObject {
@Published var names = [Name]()
}
ContentView.swift:
TextField("New Player", text: self.$newPlayer)
Button(action: self.addNewPlayer, label: {Text("Add")
.disabled(newPlayer.isEmpty)})
func addNewPlayer() {
nameStore.names.append(Name(id: String(nameStore.names.count + 1), newName: newPlayer))
self.newPlayer = ""}
Aucun commentaire:
Enregistrer un commentaire