If you like my tutorials, you will love my book . It is chockful of advanced programming techniques and the only comprehensive barcode reference for serious iOS developers.
Our DNA is written in Objective-C

__MyCompanyName__ Treats Warnings as Errors

I finally figured out three XCode settings that I’ve been dreading to change for quite a while now. See if you didn’t think of changing them yourself as well, but could not be bothered to Google them.

Are you still working for __MyCompanyName__?

If not you might want to change what XCode puts into the standard header which is being generated for all new files.

//  Report.m
//  ASiST
//  Created by Oliver Drobnik on 24.12.08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.

There is no UI method of changing this string which is kept in the XCode preferences file. Instead you have to use a command like this.

defaults write PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "";}'

The result being that from now on all code belongs to your company, even if it’s just a company of one.

//  NewClass.m
//  ForShowingOff
//  Created by Oliver Drobnik on 24.06.09.
//  Copyright 2009 All rights reserved.

The changes are made to ~/Library/Preferences/ where the wave character is short for “your home directory”. So instead of messing around on the command line you can also browse to this file with finder and double-click on it for editing.

Changing the Company Name

Set Project Default Directory

While I was scanning through these defaults I also spotted another setting that I had been dreading to change. When creating a new project it always ends up on the desktop because I am too lazy to change into my proper project directory. If only I could change this default place … yes, you can!

There is the XCProjectWizardDefaultPath. I set it to /Users/Oliver/Documents/iphone/Projects instead of the desktop. This setting change required that I restart XCode to take effect. If you now create a new project you don’t have to waste clicks navigating into the correct project folder.

default path

Treat Warnings as Errors

Warnings in XCode most of the time don’t have any effect on your code running correctly. An unused variable does not do any harm and not putting a method prototype into the class header still permits the method from being called. If you build once and receive errors you just have to build again and the warnings are no longer displayed. But they are still there.

Then there are professionals. At Tapulous they treat warnings as errors according to Jessica Kahn, Director of Engineering. Professional programmers never ignore warnings. A warning means that something is not clear or strange.

If you have skipped a warning previously you can either get it back by doing a Build – Clean or by setting the compiler flag to stop if there are warnings. This setting is not so easy to get to, many a great programmer has searched for hours not finding it. Here are the steps:

  1. Choose an iPhone Device base SDK in project settings.
  2. Select a device option in the drop down list outside.
  3. In Project Settings type “error” in the search box to see the setting “Treat Warnings as Errors”.
  4. Check it

Warnings as Errors

Step 2 is crucial because if you have Simulator selected as target device you don’t see the relevant GCC settings. The GCC 4.2 settings sections are missing then, it is still being debated whether this is a bug or a feature of XCode 3.1. Instead you see this flag as GCC_TREAT_WARNINGS_AS_ERRORS under User-Defined. Has the same effect, but confuses the developer.

With this setting activated you can no longer Build&Go if you still have warnings. So you are forced to fix those minor oversights right away.

Categories: Recipes

%d bloggers like this: