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.
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.
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.
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)
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:
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!
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/"
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/"
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