0

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!

Example

Johnathon Sullinger
  • 7,097
  • 5
  • 37
  • 102
  • 1
    Todo is a placeholder comment, not executable code, that was put there by someone as a reminder that something should go there. Sometimes, automatically generated code comes with todo comments. It means 'To do'. – Reinstate Monica Jan 27 '14 at 00:34
  • So essentially the Todo is not a separate section (treated like #pragma mark), but rather just displayed within what ever section within the jump menu that it falls within. That makes sense – Johnathon Sullinger Jan 27 '14 at 01:12

1 Answers1

2

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

Xcode project settings for Build Phases

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

Custom warnings generated from 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")
Paul B
  • 3,989
  • 33
  • 46