Customize Product Actions
There are five actions that you can perform with Xcode:
Each of these actions requires you to first build your code. Exactly what is built is specified by the scheme you choose and how that scheme is configured. In addition to the Build pane in the scheme editor, which specifies which targets are built for each action, there is a configuration pane for each action.
Run Your Application to Debug It
Although a scheme can specify any number of targets to be built when you click the action button, Xcode can launch and debug only one executable at a time. Listing 3-2 shows the Info pane for the Run action.
You can specify whether to use a debug or release build configuration (or any other build configurations you added) and which debugger to use.
Debug vs. Release Builds
A debug build includes symbols that can be used by a debugger to display your source code when your program stops at a breakpoint and to show you the values of your variables at that point. For a release build, you normally want to strip that information out, because the debug information makes it very easy to reverse-engineer the program. Release builds also typically do code optimization that isn’t done for debug builds. Because the Run action is normally used for debugging, most developers use a debug build configuration for the Run action. However, you might occasionally want to build and run your application with the release configuration to see what size your application will be and to make sure there are no problems introduced by the code optimization; that is, to make sure your application runs as you expect.
Arguments and Environment Variables
Other panes for the Run action let you provide arguments and environment variables to pass to your executable on launch, and a number of diagnostic options, such as for memory management and logging.
Specify runtime arguments for your application when you run it in Xcode.
During the test and debug phases of your product development, configure a scheme to run your application with various memory management diagnostics and logging options enabled. Schemes have a Run action with a Diagnostics pane that allows you to choose from a selection of runtime diagnostic tools.
You can simulate locations other than your current location in iOS apps that use Core Location. To set a location, choose Edit Scheme from the scheme selector in the toolbar, select the Run action, and click the Options tab. You can then choose a location from the Location menu (“Choosing a location in the scheme editor”). To set a location in the debug bar, see “Set a Location in the Debug Bar.”
Run Unit Tests to Find Regressions
Whenever you make changes to your code, there’s a chance that you’ve introduced bugs and that the code will no longer run as expected. As a quality control measure, you can create programs, called unit tests, that automatically exercise the features of your application and check the results. Each unit test is a separate bundle containing code for a set of test cases, each of which exercises some subset of your application’s features. Test cases are organized into test suites. In code, you create classes that are subclasses of the
SenTestKit test suite base class. Each such class in the bundle is a test suite, and any methods in those classes that begin with the string
test are the test cases.
Choosing the Test action causes Xcode to build the targets you specified for the test action in the Build pane of the scheme editor and then executes the test cases you enabled in the Test pane. Normally, you create one or more test targets that are separate from your application product targets.
The Xcode development installation includes a framework for testing Objective-C code—the senTestingKit framework—which provides methods you can use to exercise methods in your code and test the results.
For references and more reading on unit tests and the senTestingKit framework, see the Sen:te website.
For details about using unit tests in your project, see Xcode Unit Testing Guide.
Profile Your Application to Find Problems and Optimize Your Code
You can profile your application in order to find problems and optimize your code. Do so using the built-in Instruments application. Instruments runs your executable, collecting and displaying data that you can use to find problems such as memory leaks and unguarded file system access. It also helps you optimize aspects of execution, such as CPU use, file activity, and the use of threads. There are also specialized instruments for specific frameworks such as Core Data and OpenGL. Although you can run individual instruments, it’s common to run sets of instruments together, such as several instruments that monitor overall system activity. The Instruments application comes with a set of templates, each of which includes one or more instruments. You can also define your own templates. For more information on the Instruments application and instruments templates, see Instruments User Guide.
You use the scheme editor’s profile pane to specify which template Instruments should use when you choose the Profile action.
Open the scheme editor.
Select the Profile action.
Choose an instrument template from the Instrument pop-up menu.
The default choice is Ask on Launch, which causes Instruments to display its template chooser dialog when it starts up.
If you select a blank template from the Instruments template chooser, you can drag one or more individual instruments into the Instruments window to be run with your application. You can save the set of instruments as a custom template, in which case it becomes available as a choice in the Instrument pop-up menu of the Profile pane.
Perform Static Analysis To Find Semantic Problems
The Analyze action performs a static analysis of your code. The only option for the Analyze action in the scheme editor is whether to analyze a debug or release build. To specify which targets should be included in the analysis, use the checkboxes in the Analyze column of the Build pane. Static analysis is discussed in “Locate Possible Semantic Problems.”
Create an Archive for Sharing or Submitting Your Program
The Archive action creates an application bundle you can use to share your program with others or to submit your application to the App Store. Because it’s unusual to share a debug version of an application, most developers set the build configuration to Release in the Archive pane of the scheme editor. To distribute frameworks, plug-ins, and other targets with your application, select the checkboxes for those targets under the Archive column in the Build pane of the scheme editor. You probably don’t want to distribute unit tests with your application, on the other hand, so you should not select the checkbox for the test target in the Archive column.
For more information on the use of archives, see “Distribute Your App.”
Initiate a Product Action
You can initiate an action in several ways.
Do one of the following:
Click and hold the action button at the left end of the toolbar, then choose the action you want from the pop-up menu.
If you click this button without holding it, Xcode initiates the action currently displayed by the button.
Choose an action from the Product menu.
Use a keyboard shortcut.
There are keyboard shortcuts for every action except Archive (open the Product menu to see the list).
The action button and each of the items at the top of the Product menu (Run, Test, Profile, Analyze, Archive) cause the targets specified by the Build pane of the scheme to be built before performing the specified action. Other items in the menu allow you to build without other actions, or to perform the other actions using the last build without building again.
Hold down the Option key and Choose Product > Profile.
The scheme editor opens to give you the opportunity to check or change the scheme settings before you executing the action.
The OK button at the bottom of the scheme editor is replaced with two buttons: the name of the action (here, Profile) and Done.
Click the action button in the scheme editor.
Any changes you made to the scheme are saved and the action is carried out using the new settings.
© 2013 Apple Inc. All Rights Reserved. (Last updated: 2013-04-23)