Hello everyone,
I am trying to write a macro that, when attached to a protocol of a repository, creates an implementation of the whole repository or a subset of its functions. I would like to be able to control whether all repository functions get generated, or just a subset of them (for cases where some functions need some additional implementation, not just the "standard" implementation we use for endpoint calls).
The way I approached this is by creating a peer macro @GeneratedRepositoryEndpoints that, when attached only to the protocol, generates implementation for all functions, e.g.:
@GeneratedRepositoryEndpoints
protocol TestRepository {
func test1()
func test2()
}
// Macro Generated
final class TestRepositoryImpl: TestRepository {
func test1() {
// Implementation
}
func test2(){
// Implementation
}
}
and when attached also to some of the functions declaration in the protocol, generates implementation only for those functions, e.g.:
@GeneratedRepositoryEndpoints
protocol TestRepository {
@GeneratedRepositoryEndpoints func test1()
func test2()
}
// Macro Generated
final class TestRepositoryImpl: TestRepository {
func test1() {
// Implementation
}
}
The macro implementation works fine.
The issue I am facing is that in the second case, when I need to write the implementation of the remaining functions in the extension, the compiler does not see the macro-generated TestRepositoryImpl class, so the extension cannot be written for that.
I also tried a different approach, where the macro generated extension for the user-defined Impl class, but peer macros cannot generate extensions apparently.
Is there anything I am missing or any different approach that I could use to solve this?
Thanks in advance!