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?