UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Function giving back an error

Forums > 100 Days of SwiftUI

I am trying to complete the last challenge in the guess the flag review (To create a restart screen after 8 plays) it mentioned to create a reset() function? so I tried that but I get this error!

https://imgur.com/gXcDGxo

3      

By using reset() with the parentheses, you are actually calling the reset function and inserting its return value, which is Void.

Instead, you want to use a reference to the reset function so that the Button action will call it for you. So:

Button("Restart", action: reset)

And just FYI, you don't need to include a return type when a function doesn't return anything.

func reset() { // no need for -> Void here
//blah blah blah
}

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.