I have an problem with my code. I want to generate a random name with the array (Name.Store.names) which I used in my contentView but I get an error (var playerNames = NameStore.names).
struct GameView: View {
@State var number = Int.random(in: 0...6)
@State var randomName = Int.random(in: 0...2)
let tasks = ["..."]
var playerNames = NameStore.names
var body: some View {
ZStack {
RadialGradient(...)
.edgesIgnoringSafeArea(.all)
VStack {
Spacer()
Text("\(playerNames[randomName]) \(tasks[number])")
Spacer()
Button(action: {
self.number = Int.random(in: 0..<self.tasks.count)
self.randomName = Int.random(in: 0..<self.playerNames.count)
}) {
Text("New Task")
}
}
}
}
}
struct GameView_Previews: PreviewProvider {
static var previews: some View {
GameView()
}
}
Aucun commentaire:
Enregistrer un commentaire