XCode 13 - SwiftUI - Cannot convert value of type '(() -> Void).Type' to expected argument type '() -> Void'

struct ContentView_Previews: PreviewProvider {
    
    static var previews: some View {
        ContentView(pencilAction: () -> Void, fingerAction: () -> Void).environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
    }
}

How to pass void functions defined in UIViewController(in UIHostingController) for swiftUI button in ContentView

The simplest function which returns Void as in your example () -> Void would be {}, which is a function doing nothing and returning nothing.

I tested the toy code which works:

func doIt() {
    print("do nothing")
}

struct ContentView: View {

    var pencilAction: () -> Void
    var body: some View {
        Button(action: {
            action()
        }) { Text("Continue") }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView(pencilAction: doIt)
    }
}

You need to pass a func as pencilAction and fingerAction arguments, not the type definition.

XCode 13 - SwiftUI - Cannot convert value of type '(() -> Void).Type' to expected argument type '() -> Void'
 
 
Q