Two types of Swift macros

Two types of Swift macros

Explain # and @ in Swift - your next interview may have this question! Don’t miss it out! Shortly - # and @ are prefixes for macros in Swift. What is macro? 💡 Macro is a feature that generates code during compilation. Unlike macros in C, which work like “find and replace”, Swift macros are type-safe and context aware, making them powerful tools reducing boilerplate code. Two types of macros 1️⃣ attached - use @ prefix, tied to a declaration adding extra logic to it, like: @Test, @Model, @Observable 2️⃣ freestanding - use # prefix, standalone code like #expect, #Predicate, #warning...

November 26, 2024 · 1 min · Maciej Gomolka