thanks for your attention. I'm super suuuuper new in coding.. I think it's a very basic but I can't figure it out,,
I'm trying to make 6 random numbers! like 'powerball', 'lotto', or any kind of random unique numbers required games! I'm trying with swiftUI
I can make a one random number.. like this way
struct ContentView: View {
@State private var showDetails = false
var body: some View {
VStack {
Spacer()
if showDetails {
Text("\(Int.random(in: 1...45))")
.font(.largeTitle)
}
Button(action: {
self.showDetails.toggle()
}) {
Text("BUTT")
.padding(.bottom, 30)
}
}
}
and I can make it 6 times (Foreach) but there are overlap numbers!
And here is what I've done..
import SwiftUI
struct ContentView: View {
@State private var showDetails = false
var randomArray: [Int] = []
var randomNumbers = Int.random(in: 1...45)
var body: some View {
VStack {
Spacer()
if showDetails {
randomArray.append(randomNumbers)
Text("\(randomArray)")
.font(.largeTitle)
}
Button(action: {
self.showDetails.toggle()
}) {
Text("BUTT")
.padding(.bottom, 30)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
it show me
'Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols' 'Cannot use mutating member on immutable value: 'self' is immutable'
I think the 'randomArray' or 'randomNumers' are correct but 'randomArry.append(randomNumbers)' or Text("(randomArray)")' are maybe wrong..
I tried 2 day and I find a lot of things but I can't still make it.. so.. could you give me a little help? Thanks!
Aucun commentaire:
Enregistrer un commentaire