26

(I found the answer to this elsewhere while writing the question, but I thought it might be helpful to others if I posted it since I couldn't find anything here.)

I want to mark methods that need better error handling. I'd like them to show up as compiler warnings so other developers (who may be responsible for that area) will notice, and hopefully fix at their leisure.

(Other approaches welcome, I looked at __attribute__((warning)) but couldn't get it to work.)

2 Answers 2

51

It's very easy to do:

#warning Needs better error handling, please.
Sign up to request clarification or add additional context in comments.

5 Comments

This isn't really a good idea, as it makes warnings a regular part of the build rather than indications of possible errors. You'd be better off using //FIXME or //TODO, which many IDEs automatically pick up, to mark sections of code that need work.
@jshier I consider it developer error (or at least I would only mark ones that I consider developer error.) The idea is to help others (and myself) get better at error handling so as do the right thing going forward. The warnings will disappear when they're addressed, and I think they need to be addressed. I don't think //FIXME and //TODO are strong enough.
(Also, when you're working on a small enough team it makes more sense and isn't obnoxious because it's only seen by your target audience.)
Just be careful when you use //FIXME or //TODO. You need to add a colon at the end. The right syntax is: //FIXME: fix me comment and // TODO: to do comment
@theReverend They show up in the method list in the jump bar that's right above the code window.
4

Select your target and then select the Build Phases tab. At the bottom of the window you’ll see an option to Add Build Phase at the bottom of the screen. You can use the Add Build Phase to add a Run Script build phase. The Run Script option allows you to select a shell and execute arbitrary code against the project.

To warn about TODO & FIXME comments, use /bin/sh as the shell and paste in this script:

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

Source : Generate Xcode Warnings from TODO Comments

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.