28

Is there a way to view all TODO marks in an Xcode project?

I'm aware of how to do this in a file through the function drop down but wasn't sure how to see all in a project.

Community
  • 1
  • 1
Marcus Leon
  • 55,199
  • 118
  • 297
  • 429

4 Answers4

35

Instead of marking them as

//TODO: do something

I like to write them this way:

#warning TODO do something

That allows seeing them in the issue navigator. On production builds I even go as far as checking the "treat all warnings as errors" compiler setting.

Cyrille
  • 25,014
  • 12
  • 67
  • 90
  • 1
    This is a feature in Objective-C but however is not yet a feature in Swift. – msweet168 Mar 28 '18 at 20:16
  • I don't know in what version it was added but it is available for Swift in Xcode 10. – Vince O'Sullivan Jul 27 '18 at 08:53
  • 17
    In Xcode 10 / Swift 4.2, the syntax is now: `#warning ("TODO do something")` – stef Oct 21 '18 at 23:14
  • This does however modify your program flow. For instance, if you insert this into a function `f() { someValue }` the compile will fail. You'll have to add a `return` statement because your function becomes a multi statement function. Personally I don't like this, so I stick with a build phase solution. – Zaphod Feb 05 '22 at 20:24
13

A straight up text search is how I would do it.

Hit shift+command+F (⇧⌘F), and search for //TODO: (or however your TODOs are formatted)

mattliu
  • 823
  • 12
  • 28
13

You can add a "Run Script" Build Phase to your Target that will look through your entire project for TODO:|FIXME: marks and flag them as warnings.

This new Build Phase will then list all TODO marks as warnings in the Issue Navigator whenever you Build your project %+B.

Here's a link to Ben Dodson's tutorial for doing this with Swift files: https://bendodson.com/weblog/2014/10/02/showing-todo-as-warning-in-swift-xcode-project/

Here is a screenshot of how it looks with a project I've been working on:

Showing TODO marks as Warnings in the Issue Navigator

George Andrews
  • 279
  • 3
  • 9
10

Answer:

Besides doing a global search using the shortcut "Command + Shift + F" and finding all occurrences of TODO and FIXME, you can turn all TODOs and FIXMEs into warnings:

Navigate to Build Phases, click on + in upper left, and select "New Run Script Phase"
Put the following in the text area:

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/"

Leave all others options as is, and build your project.

Enjoy!

Modifications:

  1. If you want your own besides MARK FIXME TODO, you can make a 4th one we'll call ERROR which will highlight your line as red just like any other actual error, yet won't crash your app:

    TAGS="TODO:|FIXME:"
    ERRORTAG="ERROR:"
    find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" | perl -p -e "s/($ERRORTAG)/ error: \$1/"
    
  2. If you don't want the script to show the TODOs and FIXMEs that exist in packages installed with cocoapods, then use this modified script (still containing our ERROR tag from above):

    TAGS="TODO:|FIXME:"
    ERRORTAG="ERROR:"
    find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "${SRCROOT}/Pods/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" | perl -p -e "s/($ERRORTAG)/ error: \$1/"
    
  3. And if you install packages outside of using cocoapods (such as doing so manually or using Swift Package Manager) then you can have the script ignore everything in your workspace except for your project by putting in your project name in the path, so if your project is called "MyProject" then in the script replace find "${SRCROOT}" with find "${SRCROOT}/MyProject" so final would be (again including our ERROR tag):

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

Credit goes to Hector Matos, Zoe Van Brunt, and Noah Wilder from How to Highlight Your TODOS, FIXMES, & ERRORS in Xcode

Adam
  • 2,070
  • 1
  • 14
  • 18