Top xcode4 Questions

List of Tags
Ariel Malka

I can't find the good old "Add existing frameworks" option. How do I do this?

We're talking about Xcode 4 DP2 (in the context of iPhone development, as far as it matters...).

Answered By: Cyber ( 1365)

As per Apple's documentation:

  1. In the project navigator, select your project
  2. Select your target
  3. Select the 'Build Phases' tab
  4. Open 'Link Binaries With Libraries' expander
  5. Click the '+' button
  6. Select your framework
  7. (optional) Drag and drop the added framework to the 'Frameworks' group

How do I set up NSZombieEnabled and CFZombieLevel for my executable in Xcode 4?

Answered By: Jano ( 529)

In Xcode 4.x press


select the "Diagnostics" tab and click "Enable Zombie Objects":

Click "Enable Zombie Objects"

This turns released objects into NSZombie instances that print console warnings when used again. This is a debugging aid that increases memory use (no object is really released) but improves error reporting.

A typical case is when you over-release an object and you don't know which one:

  • With zombies: -[UITableView release]: message sent to deallocated instance
  • Without zombies: EXC_BAD_ACCESS

This Xcode setting is ignored when you archive the application for App Store submission. You don't need to touch anything before releasing your application.

Pressing ⌥⌘R is the same as selecting Product > Run while keeping the Alt key pressed.
Clicking the "Enable Zombie Objects" checkbox is the same as manually adding "NSZombieEnabled = YES" in the section "Environment Variables" of the tab Arguments.


I must be missing something obvious, but I can't figure out how to rename my project in XCode 4.

If I remember correctly XCode 3 had a dedicated menu item for this but there's no such entry in XCode 4.

Answered By: Ori ( 422)

Well, it turned out to be a trivial matter indeed.

All you need to do is click twice slowly on the project root in the project navigator and it then becomes editable. After you rename the project and press 'enter' it will suggest to automatically change all project-name-related entries and will allow you to de-select some of them if you want.



The app neither installs nor runs on my device. All provisioning profiles are up to date. I've already tried deleting and re-installing them.

The status bar shows that xcode is building my project, then it says running my project on , then it says "finished running ." Throughout this entire period, the iPod screen stays black. The iPod is being detected in the Organizer and I don't see anything wrong with its configuration. Everything was working perfectly just a couple days ago with Xcode 3.

It doesn't work on the simulator, but it may be important to note that in the simulator it appears to get stuck on "Attaching to " and the simulator refuses to start.

Answered By: MattyG ( 253)

For those reading this in regards to Xcode 4.2, and attempting to run on an earlier device (e.g. iPhone 3G, 2G, iPod 1st gen, etc) I have another solution. New projects created in Xcode 4.2 by default specify 'armv7' in the 'Required Device Capabilities'. You'll need to remove this if wanting to support devices that run armv6 (e.g. the iPhone 3G).

enter image description here

Delete armv7 from the 'Required device capabilities' in yourProjectName-Info.plist

You may also need to change the build settings to compile with armv6 instead of armv7.

This is the default:

enter image description here

Double click on 'Standard (armv7)' to add another, then click the '+' in the popup, and type in 'armv6':

enter image description here

Click done and it should look like this:

enter image description here


I would like to archive my application, but the Archive option is greyed out. What could cause this?

enter image description here

Answered By: jason ( 310)

You have to select the device in the schemes menu in the top left where you used to select between simulator/device. It won’t let you archive a build for the simulator.

Or you may find that if the iOS device is already selected the archive box isn’t selected when you choose “Edit Schemes” => “Build”.


I have an app that I developed with XCode 3 and recently started editing with XCode 4. In the Target Summary I have the iOS Application Target form with fields: Identifier, Version, Build, Devices, and Deployment target. The Version field is blank and the Build field is 3.4.0 (which matches the version of the app from when I was still editing with XCode 3).

My questions are: What is the difference between the Version and Build fields? Why was the Version field blank after I upgraded to XCode 4? Thanks.

Answered By: nekno ( 312)

Apple sort of rearranged/repurposed the fields.

Going forward, if you look on the Info tab for your Application Target, you should use the "Bundle versions string, short" as your Version (e.g., 3.4.0) and "Bundle version" as your Build (e.g., 500 or 1A500). If you don't see them both, you can add them. Those will map to the proper Version and Build textboxes on the Summary tab; they are the same values.

When viewing the Info tab, if you right-click and select Show Raw Keys/Values, you'll see the actual names are CFBundleShortVersionString (Version) and CFBundleVersion (Build).

The Version is usually used how you appear to have been using it with Xcode 3. I'm not sure on what level you're asking about the Version/Build difference, so I'll answer it philosophically.

There are all sorts of schemes, but a popular one is:


  • Major version - Major changes, redesigns, and functionality changes
  • Minor version - Minor improvements, additions to functionality
  • Revision - A patch number for bug-fixes

Then the Build is used separately to indicate the total number of builds for a release or for the entire product lifetime.

Many developers start the Build number at 0, and every time they build they increase the number by one, increasing forever. In my projects, I have a script that automatically increases the build number every time I build. See instructions for that below.

  • Release 1.0.0 might be build 542. It took 542 builds to get to a 1.0.0 release.
  • Release 1.0.1 might be build 578.
  • Release 1.1.0 might be build 694.
  • Release 2.0.0 might be build 949.

Other developers, including Apple, have a Build number comprised of a major version + minor version + number of builds for the release. These are the actual software version numbers, as opposed to the values used for marketing.

If you go to Xcode menu > About Xcode, you'll see the Version and Build numbers. If you hit the More Info... button you'll see a bunch of different versions.

For example, Xcode 4.2 (4C139). Marketing version 4.2 is Build major version 4, Build minor version C, and Build number 139. The next release (presumably 4.3) will likely be Build release 4D, and the Build number will start over at 0 and increment from there.

The iPhone Simulator Version/Build numbers are the same way, as are iPhones, Macs, etc.

  • 3.2: (7W367a)
  • 4.0: (8A400)
  • 4.1: (8B117)
  • 4.2: (8C134)
  • 4.3: (8H7)

Update: By request, here are the steps to create a script that runs each time you build your app in Xcode to read the Build number, increment it, and write it back to the app's {App}-Info.plist file. There are optional, additional steps if you want to write your version/build numbers to your Settings.bundle/Root*.plist file(s).

This is extended from the how-to article here.

In Xcode 4.2:

  1. Load your Xcode project.
  2. In the left hand pane, click on your project at the very top of the hierarchy. This will load the project settings editor.
  3. On the left-hand side of the center window pane, click on your app under the TARGETS heading. You will need to configure this setup for each project target.
  4. Select the Build Phases tab.
  5. At the bottom right, click the Add Build Phase button and select Add Run Script.
  6. Drag-and-drop the new Run Script phase to move it to just before the Copy Bundle Resources phase (when the app-info.plist file will be bundled with your app).
  7. In the new Run Script phase, leave the Shell: /bin/sh value alone. Copy and paste the following into the script area for integer build numbers:

    buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
    buildNumber=$(($buildNumber + 1))
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"

    As @AlonAmir contributed, you can use the following script instead for hex build numbers:

    buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
    buildNumber=$(($buildNumber + 1)) 
    buildNumber=$(printf "%X" $buildNumber)
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
  8. And if you have a Settings bundle where you show the Version and Build, you can add the following to the end of the script to update the version and build. Note: Change the PreferenceSpecifiers values to match your settings. PreferenceSpecifiers:2 means look at the item at index 2 under the PreferenceSpecifiers array in your plist file, so for a 0-based index, that's the 3rd preference setting in the array.

    productVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE")
    /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:2:DefaultValue $buildNumber" Settings.bundle/Root.plist
    /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $productVersion" Settings.bundle/Root.plist
  9. And if you have a universal app for iPad & iPhone, then you can also set the settings for the iPhone file:

    /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:2:DefaultValue $buildNumber" Settings.bundle/Root~iphone.plist    
    /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $productVersion" Settings.bundle/Root~iphone.plist

this is driving me crazy! I just upgraded to XCode 4 and for some reason my app won't run in the simulator or iOS device. It was working perfectly in XCode 3, but all of a sudden now when I press run the program stops at "Attaching to...". There doesn't seem to be any other info to help with this problem either. Any ideas?

For summary you can try following things to tackle the issue:

  1. Restart the simulator.
  2. Make sure that you haven't included the Info.plst file in your Building Phases -> Copy Bundle Resources.
  3. Resources folder added to the project as a folder reference (the blue folder icon). That caused the trouble, after adding the folder as a group the problem went away.
Answered By: Rob ( 95)

Fixed it!! Hopefully this helps some people avoid a very frustrating couple hours. I solved this by:

  1. Clicking on the project name in the left pane (at the very top). This will bring up a new menu to the right, something like the project/ target editors in XCode 3.
  2. Click on Build Settings up at the top.
  3. Under Packaging make sure your product name is the same for every build, and equal to whatever it says it's attaching to. Eg if XCode is Hanging at "Attaching to myLCBO" but your product name is "LCBO Finder" then it won't build. That was exactly my problem because I renamed my app half way through development.

Hope this helps!


I have problems with setting up/locating my output files in XCode4 (beta 5). They are placed somewhere in ~/Library/Developer/ugly_path/.... I can't even select "show in finder" on my products. It is the same for a simple C project, Foundation tool and even Cocoa bundle. A Debugging works fine.

Could you please point me out where and how to set up / build output directories? (I know it sounds dumb, I've been coding in XCode3 for months, but I can't figure it out in XCode4 beta).

Thanks a lot.

Answered By: the Reverend ( 243)

From the Xcode menu on top, click preferences, select the locations tab, look at the build location option.

You have 2 options:

  1. Place build products in derived data location (recommended)
  2. Place build products in locations specified by targets

Does anyone know why does Xcode 4 recommend using the first option?