Setting Up OCUnit Unit Testing in Xcode 4
Xcode ships with OCUnit, which allows you to unit test Objective-C code. This post shows you how to setup Xcode 4 so you can unit test Cocoa and iOS applications.
Create an Appropriate Project
The easiest way to add unit testing support in Xcode 4 is to create a project that uses the Cocoa or Cocoa Touch frameworks, such as a Cocoa or iOS application. When you select an appropriate project and click the Next button, you should see an Include Unit Tests checkbox.

When you select the Include Unit Tests checkbox, Xcode adds a unit test bundle target and a unit testing class to your project. Xcode also does most of the setup work for you. It configures the necessary build settings for unit testing and adds a target dependency so your application target builds when you build the unit test target.
Running Unit Tests After Building Your Project
Adding a unit test bundle when you create an Xcode project takes care of most of the build settings for you. There is one build setting you may have to setup manually. If you want Xcode to run your unit tests when you build the project, you must set the Test After Build build setting to YES. My Xcode 4: Accessing Build Settings post has detailed information on accessing build settings.
Adding Unit Test Classes to Your Project
While Xcode adds a test case class to your project when you create a new project and select the Include Unit Tests checkbox, you’ll eventually need to add more classes for unit testing. Choose File > New > File to add a unit testing class to your project. Select either Cocoa under Mac OS X or Cocoa Touch under iOS on the left side of the New File Assistant. Select Objective-C test case class from the list of file templates. Click the Next button. Enter the name of your class in the Class text field. The name of the class is also the name of the file. Click the Next button. Choose a location to save the file. Click the Create button to create the file.
Make sure the class you create is added to the unit test target, not the application target.

If you mistakenly add the unit test class to the wrong target, select the file from the project navigator and open the file inspector by choosing View > Utilities > Show File Inspector. Use the checkboxes in the Target Membership section to ensure the unit test class is a member of the unit testing target, not the application target.
Configuring Your Scheme for Testing
Click the name of the scheme in the Scheme menu and choose Edit Scheme to open the scheme editor. Select the Test step from the left side of the scheme editor.

The scheme editor allows you to choose a build configuration to use for unit testing, the debugger to use to debug unit tests, and the unit tests to run. Xcode is setup initially to run all unit tests.
Running Unit Tests
Xcode provides three ways of running unit tests. If you set the Test After Build build setting to YES, choosing Product > Build for Testing builds your project and runs the unit tests. The results of the unit tests appear in the build results window, which you can access from the log navigator. Choose View > Navigators > Show Log Navigator to show the log navigator. Select a build from the log navigator to show the build results window.
The second way to run your unit tests is to choose Product > Test (or click the Run button and choose Test). When you choose Product > Test, Xcode builds your project and runs the tests. Use the log navigator to view the results of the unit tests. The final way to run your unit tests is to choose Product > Perform Action > Test Without Building, which runs unit tests without building the project.
Adding Unit Test Support to an Existing Project
To add unit test support to an existing project, you must add a unit test target to your project. Select the name of your project from the project navigator to open the project editor. Click the Add Target button at the bottom of the editor. Select the Other group under either Mac OS X or iOS. Select Unit Testing Bundle (either Cocoa or Cocoa Touch) from the target list.

Click the Next button. Enter a name for your target in the Product Name text field. Click the Finish button to finish creating the unit test target.
Adding a unit test target to an existing Xcode project requires more setup work than creating a new project does. You must add a target dependency to the unit test target. You also must configure build settings for the unit test bundle.
Adding Target Dependencies
Adding a target dependency allows Xcode to build your application when you build the unit test target. Select the unit test target from the project editor. Click the Build Phases button at the top of the project editor. Click the disclosure triangle next to the Target Dependencies build phase. Click the + button to add a dependency. Select the application target from the target list.

Configuring the Unit Test Bundle
If you are unit testing an application, you must configure the unit test bundle. There are two build settings you must configure: Bundle Loader and Test Host. The Bundle Loader build setting is in the Linking collection, and the Test Host build setting is in the Unit Testing collection. You must set the value of these build settings to the location of the application’s executable file. For an application named MyApp, the value of the Bundle Loader and Test Host build settings would be the following:
$(BUILT_PRODUCTS_DIR)/MyApp.app/Contents/MacOS/MyApp (Mac)
$(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp (iOS)
iOS applications running in the simulator should leave the Test Host build setting blank. The simulator does not support application-hosted unit tests. If you set the Test Host build setting, you will get a warning when building the unit testing target and the tests will not run.
Downloading Xcode Without Using the Mac App Store
I have read many posts on Apple’s free developer forums from people having problems downloading and installing Xcode from the App Store. If you are having similar problems, there is an alternative to using the App Store. You can download Xcode from the following URL:
https://developer.apple.com/downloads/index.action
You can also use this URL to download older versions of Xcode.
If you don’t have an ADC account, you will need to sign up for one to download Xcode from the URL I listed. You can get an ADC account for free.
Xcode 4: Opening the Welcome Window
When you launch Xcode, the default behavior is to open a welcome window. The following screenshot shows a cropped version of the welcome window:

You can tell Xcode not to open the welcome window by deselecting the checkbox at the bottom of the welcome window. Suppose you deselect the checkbox and decide later you want to open the welcome window. How do you open it?
In Xcode 4 choose Window > Welcome to Xcode to open the welcome window.
Xcode 4.3 Changes
Apple recently released Xcode 4.3. I did not notice many changes in Xcode 4.3, not enough for me to update Xcode Tools Sensei. This post details what changed in Xcode 4.3.
The Xcode Tools Are Packaged in a Single Application
The biggest change in Xcode 4.3 is how Xcode is installed and packaged. Previous versions of Xcode required you to run an installer that installed the Xcode Tools in /Developer or another directory. Xcode 4.3 works like a typical Mac application, where the Xcode Tools appear as a single application in the Finder and install in your Applications folder. Xcode 4.3 is easier to install, uninstall, and update.
Launching Other Developer Tools
Since Xcode 4.3 is a single application you may be wondering how to launch the other tools that come with Xcode, such as Instruments. Launch them from Xcode by choosing Xcode > Open Developer Tool. Choose the tool you want to launch from the submenu. If the tool you want to launch is not in the submenu, choose More Developer Tools. Choosing More Developer Tools takes you to Apple’s developer downloads page, where you can download and install additional tools. If you want to run the Mac OpenGL developer tools that I cover in Chapter 11 of Xcode Tools Sensei, you must choose More Developer Tools and install the Graphics Tools for Xcode package from Apple’s developer page. Download the disk image and drag the applications to your Applications folder.
I don’t know how to add tools to Xcode’s Open Developer Tool menu. I downloaded the Graphics Tools for Xcode package and copied the applications to the Contents/Applications folder inside Xcode’s application bundle, but the applications did not appear in the Open Developer Tool menu. I asked about adding tools to the Open Developer Tool menu on Apple’s paid developer forums, but I have not received any answers.
Update (February 22, 2012)
I received an answer on Apple’s developer forums to my question on adding tools to the Open Developer Tool menu. You can read the solution by reading user18861′s answer to the following question on the Ask Different website:
In Xcode 4.3, where do I put the additional tools?
When the answer mentions /Applications and /Resources, it means the Applications and Resources folders inside Xcode’s application bundle.
Installing Command-Line Tools
Xcode 4.3 does not initially install a copy of command-line tools that allow you to compile programs from the Terminal. You can install the command-line tools from Xcode’s Downloads preferences.

Accessing File and Project Templates
Because Xcode 4.3 does not reside in a Developer folder, you must open the Xcode 4.3 application bundle to access things like Apple’s file and project templates. Select Xcode from the Finder, right-click, and choose Show Package Contents to examine the application bundle. The most interesting directory in Xcode’s application bundle is the following directory:
Contents/Developer
Auto Layout
Cocoa application projects created with Xcode 4.3 enable auto layout. If you don’t want to use auto layout, select the xib file from the project navigator, open the file inspector, and deselect the Use Auto Layout checkbox.
ARC Conversion
In Xcode 4.3 you can use Xcode’s ARC migration tool to convert an existing project that uses garbage collection. Xcode 4.2 could not convert a project to ARC if the project used garbage collection.
Developer Mode
When you build your first project in Xcode 4.3 an alert may open asking if you want to enter developer mode. Entering developer mode lets you do things like debug your project without Xcode asking you for your user account’s password.
Using SDL with Xcode 4
Apple changed the format for project templates in Xcode 4. The format change means the Xcode templates that ship with the Mac version of SDL don’t work in Xcode 4. If you have both Xcode 3 and 4 installed on your Mac, you can create a project that uses SDL in Xcode 3 and open it in Xcode 4. But if you’re running Xcode 10.7 and don’t have Xcode 3 installed, you’re stuck with Xcode 4 and can’t use the SDL project templates. But you can use Xcode 4 to create SDL applications without too much hassle.
Create a Cocoa Application Project
When you create a project in Xcode, select the Cocoa Application project, as you can see in the following screenshot:

The Mac OS X version of SDL is written with Cocoa so a Cocoa application project is the closest template to the old SDL project templates. Click the Next button to move to the next step where you name the project.

Deselect the Create Document-Based Application, Use Core Data, and Use Automatic Reference Counting checkboxes. SDL games don’t use Core Data or Apple’s NSDocument class. Automatic Reference Counting is for Objective-C code, which most of you won’t use if you’re using SDL. If you want to unit test your game with OCUnit, select the Include Unit Tests checkbox. My Using Xcode to Unit Test SDL Games Written in C++ post has detailed information on using OCUnit to unit test C++ code.
Click the Next button to move on to the final step of creating a project. Pick a location to save the project and click the Create button. If you want to place your project in a local git repository, select the checkbox to create the repository.
Remove Unwanted Files from the Project
Apple’s Cocoa application project template contains files that are not needed for SDL games. You can remove the xib file and source code files from the project: any files ending in .xib, .m, and .h. In Xcode 4.2 you would delete the following files: main.m, MainMenu.xib, AppDelegate.h, and AppDelegate.m. Select a file and choose Edit > Delete to delete the file from the project. An alert opens. If you click the Delete button, Xcode deletes the file instead of moving it to the Trash. Clicking the Remove Reference button is the safer option. My Xcode 4: Removing Files from a Project post has additional information on removing files from a project.
Add the SDL Framework to the Project
Now it’s time to add the SDL framework to the project. Select the project file from the project navigator to open the project editor. Select your target from the left side of the project editor. Click the Summary button at the top of the editor to see a list of linked frameworks. Click the + button to add a framework. More information on adding frameworks is in my Xcode 4: Adding a Framework to Your Project post. Click the + button to add any additional frameworks, such as OpenGL, SDL_image, and SDL_mixer.
Add SDLMain to the Project
The Mac version of SDL uses two files, SDLMain.m and SDLMain.h, that contain glue code for running SDL code on Mac OS X. The SDL project templates include these files, but in Xcode 4 you must add them to your project. Choose File > Add Files to ProjectName to add the files. After adding the SDLMain files to the project, you can start coding.
Add Search Paths
When I tried to build a SDL project with Xcode 4, I got a build error saying that the file SDL.h was not found. The solution was to add the following search path to the Header Search Paths build setting:
/Library/Frameworks/SDL.framework/Headers
You may also need to add a search path to the Framework Search Paths build setting, but I didn’t need to add a path. You may also need to specify additional search paths if you use additional frameworks, such as SDL_image and SDL_mixer. My Xcode 4: Accessing Build Settings post has detailed information on accessing build settings in Xcode 4.
Copy the SDL Framework to Your Application Bundle
The SDL Xcode project templates copy the SDL framework to your application bundle. Copying the framework to the application bundle allows someone to play your SDL game without having SDL installed. If you want the SDL framework added to your application bundle, add a Copy Files build phase to your target and add the SDL framework to the build phase.
- Select the project file from the project navigator to open the project editor.
- Select the target from the left side of the project editor.
- Click the Build Phases button at the top of the editor.
- Click the Add Build Phase button at the bottom of the editor.
- Choose Add Copy Files from the menu.
- Drag the SDL framework from the project navigator to the table in the Copy Files build phase.
- Choose Frameworks from the Destination menu.

If you have additional frameworks to copy to the application bundle, repeat Step 6 for those frameworks. Don’t copy Apple’s frameworks to the application bundle; every Mac has Apple’s frameworks installed. Only copy third-party frameworks, such as SDL_image and SDL_mixer.
Creating Custom Xcode 4 Project Templates
This post contains the material on custom project templates I had prepared for the book. The material was not strong enough to put in the book, mainly because creating custom project templates manually in Xcode 4 is difficult (much more difficult than in previous versions of Xcode) and not documented by Apple. I had a difficult time getting a simple project template to work. But there is not a lot of information available on creating Xcode 4 project templates so I’m making what I wrote available here. I hope it helps you create your own project templates.
For more information on Xcode 4 project templates, look at Apple’s templates and read the following articles, which you’ve probably read if you’ve done a Google search for creating project templates in Xcode 4:
A minimal project template for Xcode 4
About XCode 4 Project Template (How To Create Custom Project Template)
Project Template Contents
At a minimum a project template consists of two items: a folder with the extension .xctemplate and a property list file named TemplateInfo.plist. You can also have additional files like icon files, source code files, and xib files in the project template. Place these files and the property list file in the template folder.
The .xctemplate extension defines the folder as a template folder. The name of the folder is the name that appears in the list of templates for the selected category in the New Project Assistant. The name of the folder is the name of the template.
Apple’s Project Templates
I recommend duplicating the TemplateInfo.plist file from one of Apple’s templates and using that copy as your TemplateInfo.plist file. You can find Apple’s iOS project templates in the following location:
Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates
The rest of Apple’s project templates are in the following location:
Developer/Library/Xcode/Templates/Project Templates
Developer is where you installed Xcode 4.
Open the TemplateInfo.plist file in Xcode to modify it. I’m going to cover the keys in the TemplateInfo.plist file later in this post.
Moving the Template Folder
For Xcode to find your project template you must move the template folder to the user templates folder, which is in the following location:
/Users/Username/Library/Developer/Xcode/Templates/Project Templates/GroupName
You may need to manually create some of the folders in the path to the user templates folder. GroupName is the name of the category on the left side of the New Project Assistant. You can create your own group name or use one of the built-in names. Your project template will appear in the GroupName category.
TemplateInfo.plist Keys
The TemplateInfo.plist file has the following keys (this may not be an exhaustive list) for project templates:
- Ancestors
- Concrete
- Definitions
- Description
- Identifier
- InjectionTargets
- Kind
- MacOSXVersionMin
- Nodes
- Options
- Platforms
- Project
- SortOrder
- Targets
Your template does not have to use all these keys. The data type for the keys is usually one of the following: Array, Boolean, Dictionary, or String.
Ancestors Key
The Ancestors key is an array of strings. The strings are the identifiers of the project templates your template inherits from. If your template has no ancestors, you can ignore this key.
Suppose your template inherits from Apple’s Cocoa Application template. You want the same options the Apple template has to create a document-based application, to use Core Data, and to add a unit testing bundle. In this case you would need to inherit from Apple’s document-based application, Core Data application, and CoreDataSpotlight application templates. You would add the following ancestor values to your template:
com.apple.dt.unit.cocoaDocumentBasedApplication
com.apple.dt.unit.coreDataApplication
com.apple.dt.unit.coreDataSpotlightApplication
Concrete Key
The Concrete key is a Boolean value. You must set the Concrete key to YES for your template to appear in the New Project Assistant.
Definitions Key
The Definitions key is a dictionary. This key allows you to add comments, includes, and code to source code files. It also allows you to create groups from files or folders in an Xcode workspace. If you use the Definitions key to create groups, you must also have a Nodes key in your project template.
Description Key
The Description key describes the project template. The contents of the Description key appear at the bottom of the New Project Assistant when you select the project template.
Identifier Key
The Identifier key is a string value that uniquely identifies your template. It takes the following form:
com.CompanyName.TemplateName
InjectionTargets
The InjectionTargets key is an array of strings. The strings are the identifiers of project templates. The InjectionTargets key is a new key, which didn’t exist when I originally researched custom project templates. A Google search turned up no results. You’re on your own.
Kind Key
The Kind key is a string value. It should have the following value:
Xcode.Xcode3.ProjetTemplateUnitKind
If you inherit from another template, you shouldn’t have to specify the Kind key.
MacOSXVersionMin Key
The MacOSXVersionMin key is the earliest version of Mac OS X that can use the template.
Nodes Key
The Nodes key is an array key that creates a file in the project. Add a string key for each file you want to be created in the project. The value for the key is the name of the file.
Options Key
The Options key is an array that lets you add controls to the New Project Assistant. An example of a custom control is the Type pop-up menu for command-line tool projects that lets you choose the language for the project. The Type menu is an example of a custom control.
Create a dictionary key for each control you want to add. Add keys to the dictionary key. The following are common keys for controls:
- Type identifies the type of control. Pop-up menus should use a value of popup. Checkboxes should use a value of checkbox. Text fields should use a value of text. Combo boxes should use a value of combo.
- Name is the label for the control.
- Description contains tool tip text for the control.
- Identifier is a string that uniquely identifies the control.
- Default is a string that provides a default value for a control.
- Values is an array that contains the entries for a combo box or pop-up menu.
- Required is a Boolean key that says whether a condition has to be true for the control to be enabled.
You can see an example of the Required key if you create a Cocoa application. The Document Extension text field is disabled unless you select the Create Document-Based Application checkbox. If you use the Required key, you must add a RequiredOptions dictionary key that contains the conditions.
Platforms Key
The Platforms key is an array of strings that identifies the platforms the template works on. A Mac project template has the following value:
com.apple.platform.macosx
An iOS project template has the following value:
com.apple.platform.iphoneos
Project Key
The Project key is a dictionary key that contains build settings. For those of you creating project templates for personal use, I recommend using a configuration settings file instead of placing build setting values in the project template. A reason to add build settings is if you want to add libraries to the project template. Add a build setting for linker flags and add the flags for the libraries, such as -lLibraryName.
If you use the Project key to place build settings in the project template, you will most likely need to create additional dictionary keys inside the Project key. Create a Configuration dictionary key for configuration-specific build settings. Inside the Configurations dictionary, create Debug and Release dictionaries. Place your configuration-specific build settings inside the Debug and Release dictionaries. Create a SharedSettings dictionary for any build settings that apply to all build configurations. Place any build settings that apply to all build configurations inside the SharedSettings dictionary.
SortOrder Key
I’m not exactly sure what the SortOrder key does. I haven’t seen a sort order value other than 1 in Apple’s templates.
Target Key
The Targets key is an array key you use to add frameworks, libraries, build phases, and build settings to the template. The build settings you add to the Targets key apply to the target while the build settings you add to the Project key apply to the project.
To add frameworks to the template, add a Frameworks key to the Targets key. The Frameworks key should be an array. Add string keys to the Frameworks key. The value of a string key is the name of the framework. None of Apple’s project templates use a library so I don’t know what you have to do to add a library to the Target key.
To add build phases, create a dictionary key named BuildPhases. Add a dictionary key for each build phase you want in the project template. At a minimum you need to add a Class string key to the dictionary key that contains the name of the build phase. Use the following values:
- Sources is the name for the Compile Sources build phase.
- Frameworks is the name for the Link Binary with Libraries build phase.
- Resources is the name for the Copy Bundle Resources build phase.
- CopyFiles is the name for the Copy Files build phase.
- ShellScript is the name for the Run Script build phase.
- Headers is the name for the Copy Headers build phase.
- Rez is the name for the Build Carbon Resources build phase.
Xcode 4.2: Application and Logic Unit Test Classes
In Xcode 4.2 when you add a new Objective-C test case class to your project and click the Next button, you will see a Test Type menu. This menu has two choices: Application and Logic. The menu determines the unit test Xcode adds in the class’s implementation file. If you choose Application, Xcode adds a test for the application delegate. If you choose Logic, Xcode adds a dummy test that asserts 1 + 1 = 2.
It doesn’t matter what you choose from the Test Type menu. You’ll probably delete the unit test Xcode creates and add your tests. You can add your tests to both test types.
Xcode 4: Open New Tab When Double-Clicking a File
Xcode 4 adds support for tabbed editing. When using tabbed editing you most likely want Xcode to open a new tab when you open a file from the project navigator. To get this behavior you must tell Xcode to open a new tab when you double-click a file in the project navigator.
Open Xcode’s preferences. Click the General button. Choose Uses Separate Tab from the Double Click Navigation menu.

Now when you double-click a file in the project navigator, Xcode opens the file in a new tab.
Creating Custom Xcode 4 File Templates
This post contains the material on custom file templates I had prepared for the book. I decided not to put this material in the book because it wasn’t strong enough for me to support. But information on creating custom file templates in Xcode 4 isn’t easily available so I’m making it available here. I hope it helps you create your own file templates.
File Template Contents
At a minimum a file template has the following items:
- A folder with extension .xctemplate
- A property list file TemplateInfo.plist
- The file itself, which usually has the name ___FILEBASENAME___ (triple underscores)
File templates can also include additional files, such as xib files and icon files.
The .xctemplate extension defines the folder as a template folder. The name of the folder is the name that appears in the list of templates for the selected category in the New File Assistant. The name of the folder is the name of the template.
The extension for the ___FILEBASENAME___ file depends on the language. If you create a C, C++, or Objective-C template, there may be a second file for the header file.
Apple’s File Templates
The easiest way to create a custom file template is to copy one of Apple’s templates and modify it to suit your needs. Apple’s file templates also provide good examples that you can study to help you build your own templates. Apple’s iOS file templates are in the following location:
Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates
The rest of Apple’s file templates are in the following location:
Developer/Library/Xcode/Templates/File Templates
Developer is where you installed Xcode.
Making Changes to Existing Templates
After creating a copy of one of Apple’s templates, you must modify the files to customize them. Open the ___FILEBASENAME___ file and the TemplateInfo.plist file in Xcode to make your changes. I’m going to cover the keys in the TemplateInfo.plist file later in this post.
Moving the Template Folder
For Xcode to find your file template you must move the template folder to the user templates folder, which is in the following location:
/Users/Username/Library/Developer/Xcode/Templates/File Templates/GroupName
You may need to manually create some of the folders in the path to the user templates folder. GroupName is the name of the category on the left side of the New File Assistant. You can create your own group name or use one of the built-in names. Your file template will appear in the GroupName category.
TemplateInfo.plist Keys
The TemplateInfo.plist file has the following keys (this may not be an exhaustive list) for file templates:
- AllowedTypes
- CounterpartTemplateFile
- DefaultCompletionName
- Description
- Kind
- MainTemplateFile
- MacOSXVersionMin
- Options
- Platforms
- SortOrder
- Summary
Your template does not have to use all these keys. The data type for the keys is usually one of the following: Array, Boolean, Dictionary, or String.
AllowedTypes Key
The AllowedTypes key is an array that contains allowed file types. Source code file templates use this key. The following are examples of common allowed types:
- public.objective-c-source (Objective-C)
- public.objective-c-plus-plus-source (Objective C++)
- public.c-source (C)
- public.c-plus-plus.source (C++)
- public.c-header (header file for C, C++, Objective C)
- public.ruby-script (Ruby)
- public.python-script (Python)
- com.sun.java-class (Java .class file)
- com.sun.java-source (Java .java file)
- public.xml (XML)
- public.source-code (generic source code)
Use the public.source-code type for languages other than the ones I listed.
CounterpartTemplateFile Key
Only languages that have header files use the CounterpartTemplateFile key. Supply the name of the header file.
DefaultCompletionName Key
The DefaultCompletionName key contains the initial name for the file. When you save the file for the first time, this name appears as the file name in the Save panel.
Description Key
The Description key describes the file template. The contents of the Description key appear at the bottom of the New File Assistant when you select the file template.
Kind Key
Text files have the following Kind key value:
Xcode.IDEKit.TextSubstitutionFileTemplateKind
MainTemplateFile Key
The value of MainTemplateFile should be the name of the file in the .xctemplate folder. It generally has the following value:
___FILEBASENAME___.Extension (triple underscores)
Where Extension depends on the type of file you’re creating. For C, C++, and Objective-C files, the main template file is the implementation file, not the header file. The extension for an Objective-C file is .m.
MacOSXVersionMin Key
The MacOSXVersionMin key is the earliest version of Mac OS X that can use the template.
Options Key
The Options key is an array that lets you add controls to the New File Assistant. You can see an example of a custom control if you add an Objective-C class to a project. When you add an Objective-C class, there is a combo box that lets you choose the subclass. The combo box is an example of a custom control.
Create a dictionary key for each control you want to add. Add keys to the dictionary key. The following are common keys for controls:
- Type identifies the type of control. Pop-up menus should use a value of popup. Checkboxes should use a value of checkbox. Text fields should use a value of text. Combo boxes should use a value of combo.
- Name is the label for the control.
- Description contains tool tip text for the control.
- Identifier is a string that uniquely identifies the control.
- Default is a string that provides a default value for a control.
- Values is an array that contains the entries for a combo box or pop-up menu.
- Required is a Boolean key that says whether a condition has to be true for the control to be enabled.
Platforms Key
The Platforms key is an array of strings that identifies the platforms the template works on. A Mac file template has the following value:
com.apple.platform.macosx
An iOS file template has the following value:
com.apple.platform.iphoneos
SortOrder Key
I’m not exactly sure what the SortOrder key does. I haven’t seen a sort order value other than 1 in Apple’s templates.
Summary Key
The Summary key summarizes what the file template does. The summary is a shorter form of the file template’s description.
Xcode 4.2 Convert to ARC Troubleshooting
One of Xcode 4.2′s new features is compiler support for ARC (Automatic Reference Counting), which automates memory management of Objective-C objects. Xcode 4.2 includes a refactoring tool to convert an existing project to ARC. Choose Edit > Refactor > Convert to Objective-C ARC. When you convert a project to ARC, a sheet opens that walks you through the conversion. But there are a couple of problems that can occur.
Problem 1: Clicking the Save Button Does Nothing
In the last step of the conversion, Xcode shows the changes it will make to each file when it does the conversion. Clicking the Save button is supposed to complete the conversion, but you may find nothing happens when you click the Save button. The only way to close the sheet is to click the Cancel button.
You can get this problem if your project is in a git repository. Xcode is set to take a snapshot of your project when you convert it to ARC. But snapshots do not work well with git repositories. Xcode tries to take a snapshot, the snapshot fails, and Xcode stops the conversion.
The workaround is to move the .git folder out of your project folder temporarily, convert the project, and move the .git folder back. Files that start with a period are hidden by default in the Finder so you will either have to use the Terminal to move the .git folder or use a utility that shows hidden folders in the Finder.
Problem 2: Release Builds of Mac Projects Generate Build Errors
After converting your project to ARC, you may get the following error when you build your project:
-fobjc-arc is not supported with fragile abi
Xcode generates this error when you try to build a 32-bit version of a Mac application that uses ARC. ARC can build only 64-bit Mac applications. The Release build configuration is set to build both 32-bit and 64-bit Intel binaries. The error occurs when building with the Release build configuration because Xcode is trying to build a 32-bit version of your project, which ARC does not support. The solution is to set the Architectures build setting to 64-bit Intel.