TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.