I'm trying to write an macro that will expand into some SwiftUI View
. I declared my macro like this:
@freestanding(expression)
public macro FocusedCommandItem<Content : View>(_ inCommandName: String) -> Content = #externalMacro(module: "LZSwiftUIMacrosImpl", type: "FocusedCommandItemMacro")
But when I try to use it like this, I get an error:
var body: some Commands {
CommandGroup(after: .pasteboard) {
#FocusedCommandItem("Duplicate")
^ Generic parameter 'Content' could not be inferred
}
}
The code that I want this to expand into will look like:
Button("Duplicate")
{
self.duplicateCommand?.1()
}
.disabled(self.duplicateCommand?.0 ?? false)
Is there a way to write the macro declaration so it figures this out?