Skip to content

Xcode Code Snippets for Developer Warnings

Using Xcode code snippets with #warning to leave actionable reminders in your codebase.

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:

  1. Type the code you want as a snippet in any Swift file

  2. Select the code

  3. Right-click and choose Create Code Snippet

  4. Give it a title (e.g., “Developer Warning”)

  5. Set the Completion shortcut (e.g., dw)

  6. Set Availability to “All” or “Swift” scopes

  7. 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.

Found this helpful? Follow me on Bluesky and Mastodon for more Swift tips and indie dev updates.