Mac OS X Reference Library Apple Developer
Search

Building and Running Your Application

Now that you have written all the code necessary for your application to run and have built the user interface and connected the classes together, it’s time to see whether your application compiles. In this chapter, you will learn how to run the process that builds your project into an application. You will also learn how to review errors that occurred while compiling.

Build the Application

To build the Currency Converter application:

  1. In Xcode, choose File > Save All to save the changes made to the project’s source files.

  2. Click the Build toolbar item in the project window.

The status bar at the bottom of the project window indicates the status of the build. When Xcode finishes—and encounters no errors along the way—it displays “Build succeeded” in the status bar. If there are errors, however, you need to correct them and start the build process again. See “Correct Build Errors” for details.

Extra: Check Out the Documentation

Xcode gives you access to ADC Reference Library content. You can jump directly to documentation and header files while you work on a project. Try it out:

  1. Open the ConverterController.m file in an editor window.

  2. Option–double-click the word setFloatValue in the code. (Hold down the Option key and double-click the word.) The Quick Help window appears with a summary of the reference documentation. Click the book icon to get to a complete description of the selected method. Read more in “Expanding on the Basics.”

  3. Close the Quick Help window.

  4. Command–double-click the same word. A pop-up menu with a list of method names appears.

  5. Choose [NSCell setFloatValue]. This time, Xcode displays the NSCell.h header file in an editor window and highlights the declaration of the setFloatValue method.

  6. Close the header file.

Run the Application

Your hard work is about to pay off. Because you haven’t edited any code since the last time you built the project, the application is ready to run.

  1. Choose Build > Build and Go.

  2. After the Currency Converter application launches, enter a rate and a dollar amount.

  3. Click Convert.

  4. Select the text in a text field and choose the Currency Converter > Services submenu.

    The Services menu lists other applications that can operate on the selected text.

  5. Choose Currency Converter > Quit Currency Converter from the application menu to quit Currency Converter.

Correct Build Errors

Of course, rare is the project that is flawless from the start. For most applications you write, Xcode is likely to catch some errors when you first build them. Thankfully, Xcode offers tools to help you catch those bugs and move on.

  1. To get an idea of the error-checking features of Xcode, introduce a mistake into the code and click Build again.

    You can now see that the left column of your code contains one or more error indicators.

    While the error indicator helps you understand the location of the error, you may want to examine the nature of the problem.

  2. In the project window, click the Build Results tab.

  3. Double click the error to open it in an editor window and display the error.

  4. Fix the error in the code and build the application again. The errors go away, and the status bar indicates that the build was successful.

Great Job!

Although Currency Converter is a simple application, creating it illustrates many of the concepts and techniques of Cocoa programming. Now you have a much better grasp of the skills you need to develop Cocoa applications. You learned:

What’s Next?

In this chapter, you learned how to build and run your application. You also learned how to identify and resolve build errors. In the next chapter, you learn how to set properties such as your application’s name and copyright information. You also learn how to give your application a custom icon.




Last updated: 2009-08-03

Did this document help you? Yes It's good, but... Not helpful...