ssly
(Fangchang)
1
For example, I have two different member macros that can generate some new methods for a struct. When I need to use them simultaneously, I have to invoke them sequentially. I'm wondering if there is a way, similar to the '&' in protocols, to combine different macros.
@macroA
@macroB
struct Test {}
@macroA&B
struct Test {}
I tried using expression macros to invoke other macros, but I found that the code generated by macros is not subject to second-level expansion by the compiler, and this approach doesn't work.
#macroA&B
// @macroA ERROR: Expected macro expansion to produce an expression
// @macroB ERROR: Expected declaration
struct Test {}
Is there any other way to meet my requirements? I urgently need to combine some macros with small granularity of functionality.
I don't think there is a way to combine them. Certainly, the & operator won't help here.
My recommendation is to define a third macro, that does what the two other macros macroA and macroB would do together.
ssly
(Fangchang)
4
Up to now, I defined new macros to achieve this, which results in some duplicated logic code and has caused trouble in subsequent maintenance. I hope that Swift's official support for such features can be considered in the future