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

Tried to use .alert without trailing closure and I am getting this Error

Forums > SwiftUI

.alert("Button was pressed", isPresented: $showingAlert, actions: {() -> View
                        Button("Ok"){}
                        Text("Alright")
                        Button("Ok"){}
                        Button("Ok"){}
                    })

Here is my code. I wanted to try to use a normal closure for this but i keep getting error: Type 'any View' cannot conform to 'View'

can someone please help me understand what is wrong here?

   

.alert has a number of different option but think you are using this on

.alert(titleKey: LocalizedStringKey, isPresented: Binding<Bool>, actions: () -> View)

As you can see that take a String for title, a Bool for isPresented and for the action take a closure that take no parameters and return View

in your example you have left the placeholder () -> View if you remove then it should work.

   

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.