(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.)
Swift has compiler directives that help us mark such issues in our code: #warning and #error . The former will force Xcode to issue a warning when building your code, and the latter will issue a compile error so your code won't build at all.
Compiler warnings are messages produced by a compiler regarding program code fragments to be considered by the developer, as they may contain errors. Unlike compilation errors, warnings don't interrupt the compilation process.
The full list of warnings should be visible in the output window. After building open the output window, switch it to the build output and you should have access to all errors emitted by the compiler.
It's very easy to do:
#warning Needs better error handling, please.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With