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

Note:

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:

#warning("message")
#error("message")

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

iOS Size Classes Cheat Sheet

Subscribe and also get my free iOS Size Classes Cheat Sheet

Success! Now check your email to confirm your subscription and download your free guide to iOS Size Classes.

There was an error submitting your subscription. Please try again.

Unsubscribe at any time. See Privacy Policy
No time to watch WWDC videos?

Sign up to get my iOS posts and news direct to your inbox and also get my free iOS Size Classes Cheat Sheet

OK! Check your inbox (or spam folder) for an email to confirm your details and download your free guide to iOS Size Classes.

There was an error submitting your subscription. Please try again.

Unsubscribe at any time. See Privacy Policy
Archives Categories