NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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!


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


Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until October 1st.

Click to save your free spot now

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.