NEW: Learn to build amazing SwiftUI apps for macOS with my new book! >>

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

1      

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
}

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Spend less time managing in-app purchase infrastructure so you can focus on building your app. RevenueCat gives everything you need to easily implement, manage, and analyze in-app purchases and subscriptions without managing servers or writing backend code.

Get Started

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

Reply to this topic…

You need to create an account or log in to reply.

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.