I'd like to create a macro that generates some properties and also applies another macro. Essentially an "extension" of the existing macro.
Is this possible?
@FooObservable
final class User {
let id: Int
var name: String
}
Which would generate a type that has the @Observable macro applied in addition to having some external functions that could then depend on the type being Observable.
I'm basically looking to compose one macro with some additional features.
For example, @FooObservable would be a macro that does two things:
Applies @Observable to the type.
Adds a function func foo() to the type.
The catch is - func foo() will have its implementation dependent on the type being Observable, so it wouldn't make sense to be an entirely separate macro.
e.g.
@FooObservable
class User {
let id: Int?
let name: String
}
// would generate...
@Observable
class User {
let id: Int?
let name: String
func foo() {
print("Hello from Foo!")
}
}
I don't think this is possible at this time. There is a memberAttribute macro but no attribute macro. I feel like this is kind of a hole, but I think it's done purposefully.