Todo in Xcode

Dec 26, 2020 2 min read
Todo in Xcode

Commenting notes around your project helps you and your colleagues keep track of work that has been done, and what work still needs to be done.

The practice of leaving notes is important.

Commenting notes around your project helps you and your colleagues keep track of work that has been done, and what work still needs to be done.

Three keywords (TODO, FIXME, and MARK) have built in functionality in Xcode to help keep track of the many things that need to be done in your project. Additionally, with a little help from scripting, you can extend the functionality of these keywords to make sure your notes don’t go unnoticed.

We have the following to work on:

  1. //TODO: Some note...
  2. //FIXME: Some note...
  3. //MARK: — Some note...

By using a little bit of bash, Xcode will automatically throw you a warning or an error for any given comment tag.

Go to the build phases on your Xcode project file.

Click on the little plus sign at the top left and select New Run Script Phase:

The idea here is that you’re adding another step to the build process when Xcode builds your project. If you unwrap the arrow for the run script item, you’ll see a black box that will hold script that Xcode will run on every build.

The code above can be found here:

TAGS="TODO:|FIXME:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"

If you want to NOT include the TODOs in your Pods or somewhere else, replace ${SRCROOT} with the name of your project. Then it will only check in that directory.

Now build your program. If you have any //TODO: or //FIXME: tags, Xcode will throw you a warning. If you write in an //ERROR: tag, Xcode will throw you an error and not run. (Note: you may have to move your script up in the build order.)

Employ this little trick, and never leave another item on your TODO list undone!

Great! Next, complete checkout for full access to ArturoFM.
Welcome back! You've successfully signed in.
You've successfully subscribed to ArturoFM.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.