Special comment marks
Not sure if there is a // TODO
special comment mark. There are TODO:
, FIXME:
, MARK:
, MARK: -
(to put separator). MARK: - Some Text
will put a some text with separator. Also there are // ???:
and // !!!:
- they produce marks as well - just try them (they might not work in Swift).
// TODO
without :
does not create any marks (as of Xcode 10).
Highlighting comment marks by turning them into Xcode warnings
You can use certain types of comments to produce warnings at build time.
Select Project -> Build Phases
, press '+' button to add another phase. Choose Run Script
on creation. Add as a body of script (make sure Shell is /bin/sh
):
KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -name "*.swift" \) -print0 | \
xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | \
perl -p -e "s/($KEYWORDS)/ warning: \$1/"

Now when you build, you'll get warnings with the text of comments.

You are free to limit KEYWORDS to fixes and !!! only.
To get these warnings upfront (and not wait for the actual build) just move the newly created Run Script
section to the top.
Some variations of this solutions can be found here and here.
Throwing custom compile time warnings and errors
In case you need to explicitly rise a warning for some piece of your code Swift allows for the following compile directives:
#if os(iOS)
#warning("this code is untested in iOS")
#endif
Or
#error("Throws a build error")