BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

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 In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

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.