I had a question about lesson 10 (buttons). I’ve looked at a lot on the internet trying to get my console to display the action: { print (“hello world”), yet nothing is working (the surrounding code is correct since I copied it from Chris’ video). Here some of thing things I’ve tried:
1 restarting Xcode and my computer
2 opening and closing the debugging console in different ways
3 making sure the correct Xcode behaviors boxes are checked
Here is my code:
import SwiftUI
struct ContentView: View {
//can reference in any part of this structure
@State var playerCard = "card5"
@State var cpuCard = "card9"
@State var playerScore = 0
@State var cpuScore = 0
//get notification of changes and update automatically
var body: some View {
ZStack {
Image("background") .ignoresSafeArea()
//start of actual stuff
VStack{
Spacer()
Image("logo")
//cards
Spacer()
HStack{
Spacer()
Image(playerCard)
Spacer()
Image(cpuCard)
Spacer()
}
Spacer()
//make button
Button(action: {
//update the cards
print("hello world")
playerCard = "card11"
cpuCard = "card12"
//need a property wrapper
//state property wrapper
//update the score
playerScore+=1
cpuScore+=1
}
, label: {
Image("dealbutton")
})
Spacer()
VStack{
HStack{
Spacer()
Text("Player").font(.headline).fontWeight(.bold).foregroundColor(.white).padding(.bottom, 10.0)
Spacer()
Text("CPU").font(.headline).fontWeight(.bold).foregroundColor(.white).padding(.bottom, 10.0)
Spacer()
}
HStack{
Spacer()
Text(String(playerScore)).font(.largeTitle).foregroundColor(.white)
Spacer()
//pass in int into string
Text(String(cpuScore)).font(.largeTitle).foregroundColor(.white)
Spacer()
}
}
Spacer()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}