#warning, we’ve lost #pragma mark

Swift introduced cool stuff, but also removed some essentials. For example, checking the #warning tags before submitting helped us prevent submitting an app with the test environment enabled. In Swift, there’s no more #warning and #pragma mark tag. There is instead a new way to create a #pragma mark using the following syntax:

// MARK: UITableViewDelegate
// TODO: Implement this method
// FIXME: This bug needs to be fixed!

This helps us creating an overview. However, Apple wants us to use extensions instead to create this overview. In my opinion, a combination of both is the best:

// MARK: UITableViewDelegate
extension viewController : UITableViewDelegate 

Which gives us the following overview:
Pragma mark and extensions

But what about the warnings?

To use the #warning tag in Swift, there’s a little run script to bring back this functionality:

if [ "${CONFIGURATION}" = "Debug PROD" ]; then
TAGS="TODO:|FIXME:|WARNING:"
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/"
fi

This creates warnings for all your // TODO:, // FIXME: and // WARNING: comment lines. Make sure to match your configuration and add this as a runtime script in your Xcode build phases configuration

 

Antoine van der Lee

Dutch iOS developer at Triple. Developed apps like Buienradar, Videoland and Pop the Dots.

 
Follow on Feedly