In the previous post on GCC and unused values, I made a change to a compiler option such that statements that have no effect are flagged as warnings. Problem is, this change only applies to the current project. For all new projects you create, you will have to make the same change. There is a better way…
If we change the project templates for Xcode to include the compiler option which checks for unused values, each new project going forward will make this check. Here’s how to do that:
Step #1 – Locate the iPhone project templates. On my system, they are located here:
Notice in the figure below the six types of iPhone project available. These coincide to the project types that appear in Xcode when you choose to create a new iPhone OS application.
Step #2 – Open one of the project folders, and from within the folder, right click (or Control-click) on the __PROJECTNAME__.xcodeproj.
We need to right click on the entry as this entry is actually a folder (package), and thus cannot be opened directly with a text editor. See the figure below:
Step #3 – From the right click menu, choose ‘Show Package Contents’
Step #4 – One of the entires in the package is ‘project.pbxproj’. Open this file with a text editor (text edit will do just fine). See the figure below:
Step #5 – Search the project file for ‘GCC_WARN_UNUSED_VARIABLE’
Step #6 – Just below the entry for ‘GCC_WARN_UNUSED_VARIABLE’ add this entry: ‘GCC_WARN_UNUSED_VALUE = YES;’
There should be two places to make this change, one in the Debug and one in the Release compile options. See the figure below which shows the GCC_WARN_UNUSED_VALUE added to both sections.
From this point forward, for this project type, you will now have the GCC_WARN_UNUSED_VALUE compiler warning included as one of the compiler options.
You can run through the same steps for each of the six project types available for iPhone OS applications.
If there are other settings you would like to include as well, now’s the time to do it. To learn more about the options available, from a terminal window enter man gcc. A search on Google will also provide a wealth of information on various compiler options and recommendations.