//TODO: — Make your notes on Xcode stand out

Christopher Boynton
4 min readOct 25, 2016

--

The practice of leaving notes is important.

Pictured: J. Walter Weatherman

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.

Play along at home to see how this works!

Keywords

In Xcode, open up a .swift file. Above your code editor you’ll see a status bar, that shows the location of your swift file, as well as a where you currently are within the file.

Find this above your code editor

Clicking on this last item will show a dropdown menu, listing the properties, methods, or whatever else is happening in your file. This helps read and navigate files with many lines of code, with many functionalities.

Your table of contents

Xcode also allows you to place your own items in this list, so that others, or maybe even yourself after a long week, can get a quick diagnostic on the file to see if things need to be done or need to be fixed.

For example:

//TODO: Add method to find needle in a haystack

…will produce this, with a bulleted list icon:

This:

//FIXME: Remove all references to jiltedExLover

…will produce this message, with an bandage icon:

For another trick, adding a dash (-) after the colon on any note will create a line break in your dropdown list. So this:

//MARK: — Distinct Section

…will produce this message with a line break over it:

Got it? Great!

Generating Warnings and Errors with Comments

Now maybe you’re thinking, what’s the point? Don’t I still have to dig through the program, going file by file, clicking the dropdown menu, trying to find that TODO tag? What if the project has dozens of files? Won’t my TODO and FIXME tags get lost in the mess and forgotten? If only there was a way to get Xcode to give you a warning if a TODO tag is left unanswered!

Guess what?

There is!

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.

Select the project, then move to the build phases

Click on the little plus sign at the trop right and select Run New 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 run script box

Now copy and paste this into that box:

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!

--

--

Christopher Boynton

iOS Student at the Flatiron School with a passion for algorithms and animation.