In Objective-C Xcode generate compile time warning by using #warning preprocessor directive in your code. Unfortunately, this is not available when using Swift.

Sometime artificial warnings serve as an active reminder to fix your code or to implement some TODO issues.For example, checking the warnings before submitting can help us to prevent submitting an app with the staging base url.

To get warnings for tags like TODO, FIXME and WARNING in Swift we need to add little Run Script.

Just do the following:

  1. Select your app target in the project overview.

  2. Click on the Build Phases tab.

  3. Click on + in the top-left to add a new phase.

  4. Select New Run Script Phase.

In the allocated space for the script,enter the following:

echo "searching ${SRCROOT} for ${TAGS}"
find "${SRCROOT}" \( -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"

This creates warnings for all your // TODO:, // FIXME: and // WARNING: comment lines. Now to create an artificial warning in your code just use either of the following:

// TODO: Here is something you need to do.
// FIXME: This you need to fix.
// WARNING: This warning should be removed.