flâneur — a map of the web's best reading

Macros | Documentation

docs.swift.org · 92 words · saved by 1 readers

Macros transform your source code when you compile it, letting you avoid writing repetitive code by hand. During compilation, Swift expands any macros in your code before building your code as usual. Expanding a macro is always an additive operation: Macros add new code, but they never delete or modify existing code. Both the input to a macro and the output of macro expansion are checked to ensure they’re syntactically valid Swift code. Likewise, the values you pass to a macro and the values in code generated by a macro are checked to ensure they have the correct types. In addition, if the macro’s implementation encounters an error when expanding that macro, the compiler treats this as a compilation error. These guarantees make it easier to reason about code that uses macros, and they make it easier to identify issues like using a macro incorrectly or a macro implementation that has a bug. Swift has two kinds of macros: Freestanding macros appear on their own, without being attached to

To navigate the symbols, press Up Arrow, Down Arrow, Left Arrow or Right Arrow No items were found 1 item was found {number} items were found. Tab back to navigate through them. re looking for can't be found."},"color-scheme":{"select":"Select a color scheme preference","auto":"Auto","dark":"Dark","light":"Light"},"accessibility":{"strike":{"start":"start of stricken text","end":"end of stricken text"},"code":{"start":"start of code block","end":"end of code block"},"skip-navigation":"Skip Navigation","in-page-link":"in page link"},"select-language":"Select the language for this page","icons":

Explore this link on the map →

related reading