Your First iOS and SwiftUI App · Challenge: Starting Over | raywenderlich.com


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

Hello,

Question regarding this “Start Over” Challenge. The way I solved it was by entering the following code in my button action pasted below:

indent preformatted text by 4 spaces

// start over button
Button(action: {
print(“Start over button was hit”)
self.startOver = true
self.score = 0
self.round = 1
self.target = Int.random(in:1…100)
self.sliderValue = 50.0

                })

The app worked and I saved myself from writing a function, is this ok? Or not best practice?

@divdoge Thank you for sharing your solution - much appreciated!