Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you add custom compiler warnings in Objective-C?

Tags:

(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.)

like image 409
zekel Avatar asked Jun 02 '11 20:06

zekel


People also ask

Which Swift compiler directive will force the compiler to issue an error?

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.

What is compiler warning in C++?

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.

How do I see compiler warnings in Visual Studio?

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.


2 Answers

It's very easy to do:

#warning Needs better error handling, please. 
like image 129
zekel Avatar answered Sep 17 '22 01:09

zekel


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

like image 22
Abhishek Bedi Avatar answered Sep 20 '22 01:09

Abhishek Bedi