Ad

Our DNA is written in Swift
Jump

__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 com.apple.Xcode PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "Drobnik.com";}'

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 Drobnik.com. All rights reserved.
//

The changes are made to ~/Library/Preferences/com.apple.Xcode.plist 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

0 COmments »

  1. Hi Oliver,

    There is an easier way I’ve found for updating the __MyCompanyName__ in the default templates. I’ve found that, at least in the latest XCode builds, if you have a company name set for your Address Book card, it will get pulled into the source the next time you create a new file.

    Thanks for the tip about the treat warnings as error; I’d been looking for that for a while but couldn’t be bothered to google for it.

    Cheers,

    James

  2. Thank you. I’ve been looking for a way to change the company name for a while. Now I don’t have to change it manually, not that that setting really matters, but it looks better when it is set.

    As for setting the default location, somehow it has already been set to the right location for me. I’m assuming that it changes it if you use a location other than the default one multiple times.

    Also, thanks for the tip about treating warnings as errors. I never leave warnings alone, but this will help make sure of that.