How should one proceed if the name of the new method added by the macro is not a constant?

Can macros only add new variables or methods with fixed names?

Macros can add arbitrary names, except at the global scope:

@attached(member, names: arbitrary)
public macro MyMacro() = ...

From the book:

The macro declaration also includes arbitrary after the list of names, allowing the macro to generate declarations whose names aren’t known until you use the macro.

1 Like

Unfortunately, I want to use a peer macro to generate a top level new type :pensive:...