TODO FIXME And Compiler Directives

Want to be sure you don’t ship code without doing your TODO’s or fixing your FIXME’s? Take a look at the new compiler directives added in Swift 4.2.

Xcode Annotations

Xcode supports a number of annotations to source code that will show up in the navigation jump bar. Here is an example of an annotated view controller:

import UIKit

// FIXME: Leaking memory

// TODO: -
// TODO: Refactor data source and navigation
// TODO: Need to localize strings
// TODO: -

class TaskTableViewController: UITableViewController {

  // MARK: - UITableViewDataSource -

  // MARK: - Storyboard Seque -

As well as being a visual reminder in the source code Xcode also uses the annotations in the jump bar navigation menu:

Xcode Jump Bar Menu


Swift Compiler Directives

The Xcode annotations show up in the jump bar menu but not much else. The compiler ignores them so you can ship without doing your TODO’s or fixing your FIXME’s. They also do not show up in command-line builds.

Swift 4.2 has a couple of new compiler directives that go a step further and cause build-time warnings and errors:


You use them like this:

func viewSetup() {
    #warning("Strings are not localized")

func updateView() {
    #error("Accessing UI on wrong thread")

Compare the warning and error compiler directives to the TODO and FIXME annotations. This time the compiler generates a warning and error message that are visible in the source code editor and will also show up in command-line builds:

Compiler warning and error directives

Much harder to ignore.

Learn More

Never Miss A Post

Sign up to get my iOS posts and news direct to your inbox and I'll also send you a PDF of my WWDC Viewing Guide

    Unsubscribe at any time. See privacy policy.

    Archives Categories