Discussion on Macro Annotation Functionality

Before the introduction of Swift macros, I had been using Sourcery for some metaprogramming tasks. Sourcery comes with annotation functionality, allowing it to generate highly customized code. However, in Swift macros, I haven't found a similar feature. Currently, I am using a custom supplementary macro to achieve a functionality similar to annotations.

For example, In the macro for automatically generating Codable-related code, I have customized two attached macros to implement custom default values for the Decoder and custom CodingKey.

struct Test {
  let name: String
  let age: Int

However, recently, when I attempted to use MemberAttributeMacro to add annotations in bulk, I found that macros generated by MemberAttributeMacro were not recognized by other macros in declaration.attributes.
like this:

This looks like a resolution order issue or something else.
When I don't use MemberAttributeMacro and manually add macros for each member, the result looks like this.

I want to know if there is a more official way for annotation functionality or if better support can be expected in the future.

1 Like