Why #warning Matters During Development
Swift’s #warning directive generates a compiler warning with a custom message. Unlike comments, these show up in the Issue Navigator and in the build output, making them impossible to miss. I use them as hard reminders for things that must be addressed before shipping.
Two Snippets I Use Daily
I have two Xcode code snippets configured for this purpose.
“nyi” – Not Yet Implemented:
#warning("Not yet implemented!")I type nyi and hit Enter whenever I stub out a function or skip a code path during prototyping. It compiles fine but the warning ensures I come back to finish the work.
“dw” – Developer Warning:
#warning("<#message#>")This one uses a placeholder token so that after typing dw and pressing Enter, the cursor lands inside the message and I can type a custom note. I use this for things like #warning("Handle error case for offline mode") or #warning("Remove before release").
How to Create Xcode Snippets
Setting these up takes about 30 seconds each:
Type the code you want as a snippet in any Swift file
Select the code
Right-click and choose Create Code Snippet
Give it a title (e.g., “Developer Warning”)
Set the Completion shortcut (e.g.,
dw)Set Availability to “All” or “Swift” scopes
Click Done
From that point on, typing the shortcut in any Swift file offers the snippet via autocomplete.
The key advantage over plain comments is visibility. A // TODO: comment is easy to ignore and hard to search for consistently. A #warning forces the compiler to surface it every single build, keeping your unfinished work front and center until you resolve it.
