Your First iOS & SwiftUI App: Polishing the App, Episode 16: The Xcode Debugger | raywenderlich.com

There’s a subtle bug where Bull’s Eye doesn’t calculate the correct score. Learn why this is happening, and how to fix it, with the power of the Xcode Debugger.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/28797859-your-first-ios-swiftui-app-polishing-the-app/lessons/16

For those on iOS 15, to get the target number to reset AFTER you click the dismiss button titled “Awesome”, your code will look different from Ray’s.

Basically you just put the game.startNewRound(points: game.points(sliderValue:Int(sliderValue))) inside the curly braces that directly follow Button("Awesome")

I used this and it worked:

  .alert("Hello There!", isPresented: $alertIsVisible) {
            Button("Awesome") {game.startNewRound(points: game.points(sliderValue:Int(sliderValue)))}
        } message: {
            let roundedValue = Int(sliderValue.rounded())
            Text("The slider's value is \(roundedValue).\n" + "You scored \(game.points(sliderValue: roundedValue)) points this round.")
    }
}
1 Like