Using swift macro to add SwiftUI ViewModifier

Hello everyone.
I have been searching for a solution to the following problem using macros without being able to achieve a successful result. Basically, I am trying to add a SwiftUI ViewModifier through a macro, something like this:

@Trackable
struct SomeView: View {
    var body: some View {
        Text("A")
        Text("B")
    }
}

That expands to:

struct SomeView: View {
    var body: some View {
        Text("A")
        Text("B")
        .track(name: "some_view")
    }
}

So far, I haven't found a way to do this. I even have the feeling that it might not be possible because this operation feels more like a modification rather than an addition, which wouldn't be allowed by the definition of macros:

Expanding a macro is always an additive operation: Macros add new code, but they never delete or modify existing code.

Maybe I'm overlooking something, and there might be a possibility. Is this possible?

1 Like

It looks like that would require a function body macro, and that feature is still in progress.

Thanks @David_Catmull, that's e̶x̶a̶c̶t̶l̶y̶ almost what I was looking for