问题
Can some one tell me if this is how the IDE is supposed to work or if I am not understanding how the // TODO commenting feature works. When I place a // TODO, Xcode adds a TODO section in the jump bar. Multiple TODO's places multiple sections with the TODO comment as the section title.
The issue that I am seeing, is that any method that comes after my TODO comment is included as part of the TODO section in the jump bar. Why does is Xcode just automatically adding all of the methods after my comment as part of the TODO ?
Perhaps I am missing the point of why it does this, or maybe I am doing this wrong. Could someone provide some clarification on this for me?
Thanks!
回答1:
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).
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.
来源:https://stackoverflow.com/questions/21371221/using-the-todo-comment-with-the-xcode-ide