Upgrading to Xcode 4

I thought it might be useful to share some of the issues/experiences I have seen moving projects from Xcode 3 to Xcode 4. Most of the issues are actually fairly minor once you figure out what is going on.

You Can Always Go Back

First things first. Of course you have all of your code checked into a secure version control system in case anything goes wrong. But it also good to know that if you start to play with an existing Xcode 3 project in Xcode 4 you are not making a one time switch which you will then have to live with for ever more.

Both Xcode 3 and Xcode 4 share the same project structure so you can switch back and forth as often as you want. You can open an existing Xcode 3 project with Xcode 4, use it for a while and then close it and open it again with Xcode 3. Xcode 4 adds a number of additional settings and workspace files to the .xcodeproj directory but these are ignored by Xcode 3. You probably want to avoid opening the same project in Xcode 3 and 4 at the same time though…

Git Ignore File Changes

Since Xcode 4 adds some additional project files I found it useful to add a couple of extra lines to my .gitignore file:

*.xcodeproj/project.xcworkspace/*.xcodeproj/xcuserdata/

This of course assumes that you do not want to check your workspace settings into your Git repository

Finding Your Archives

Xcode 3.2.2 introduced a Build and Archive option to allow builds to be archived prior to submitting to the App Store. You can view and submit an archived App from the Xcode Organizer. Xcode 4 has a similar feature except that it stores the archives in a different location. This means that when you open the project with Xcode 4 and look in the Organizer the archived builds are missing.

Xcode 3 stores the archives under the users home directory at:

~/Library/Application Support/Developer/Shared/Archived Applications/

Xcode 4 stores the archives at the following location:

~/Library/Developer/Xcode/Archives/YYYY-DD-MM/

One thing to note with Xcode 4 is that creating an archive that shows up in the Organizer is a two step process. First from the Product menu use Build For -> Build For Archiving and then use Product -> Archive and you should see the archived build show up in the organizer.

Choose Your Compiler

As I mentioned in a previous post the default compiler option for new projects has changed to LLVM GCC 4.2 in Xcode 4. For an existing project you may want to review which compiler you are using (GCC, LLVM GCC or pure LLVM 2.0).

You can of course switch to LLVM GCC or LLVM 1.7 in Xcode 3 so you do not have to wait until you switch to Xcode 4. However, in my case, switching over to Xcode 4 was a good point to stop and think about which compiler to use.

Improved Syntax Checking

Even if you do not plan on moving over to Xcode full-time it is well worth using it to review your existing projects. I came across a number of syntax errors in some old code of mine just by opening the project in Xcode 4. Some of these errors were minor annoyances but still good to clean up.

One odd example was that I had a number of #include statements that were terminated with a “;”. A harmless mistake but Xcode 4 identified it as an extra token and suggested as a fix to insert a comment. In this case a better fix is just to delete the extra semicolon but that is a minor detail.

Format strings are validated much more strictly, the following code generates a warning with Xcode 4:

NSNumber *value = [NSNumber numberWithInteger:100];
NSLog(@"Log the value: %d",value);

The format string specifies %d so it expects to see an integer when it is in fact being passed an NSNumber. Another common error it will warn about is if you have forgotten to synthezise accessors for a property. I saw this several times for an ivar that I had added to a class but then never actually used.

I also found an old piece of code where I was doing the following:

-(id)init {

  if (self = [super init]) {
    // init some stuff
    ...
  }

  return self;
}

This generated a warning about a semantic issue as follows:

Using the result of an assignment as a condition without parentheses

Cleaning up the init method syntax removed the warning:

-(id)init {

  self = [super init];
  if (nil != self) {
    // init some stuff
    ...
  }
  
  return self;
}

The Learning Curve

Moving over to Xcode 4 involves a pretty steep learning curve. It takes a while to get the hang of the new organisation and at first I found myself fighting the interface. The introduction of Workspaces and Schemes means that the build settings are no longer where they used to be. Other features like the Jump Bar for navigation have a lot of advantages but still seem to lack some polish.

The only advice I can really give is to stick with it. Many of the rough edges will hopefully get smoothed over in future releases. The other thing you should do if you are a registered developer is watch some of the WWDC 2010 sessions on Xcode 4. Some of the details are now out of date but it is still useful to get a tour of the new layout and features. Try the following sessions to get started:

  • 307 - Introducing Xcode 4
  • 308 - Developing Your App with Xcode 4
  • 315 - Using Interface Builder in Xcode 4

Stability and Performance

One of the biggest complaints about Xcode 4 is the overall stability. I gave up with some of the earlier developer previews. The current release seems to be a huge improvement but I still see the occasional crash. I don’t remember the last time I experienced a crash with Xcode 3.

The other issue I have is that I find the UI performance can be slow on my 3 year old iMac (time for an upgrade?). The performance has certainly improved from the early previews but there are still times particulary with the Organizer when accessing documentation when I find myself clicking twice due to the slow response.

Wrapping Up

There are a lot of new features in Xcode 4 and unfortunately I guess there is no gain without some pain. The issues I have seen so far have been fairly minor and mostly related to learning the new UI. I find myself slowly adopting Xcode 4 more and more to the extent that I finally feel comfortable with the new layout. Keeping backward compatibility with Xcode 3 provides a very nice safety net though should there be a problem.