Documentation Archive Developer

Getting Started

To create the Mac app in this tutorial, you need Xcode 4.4 or later. Xcode is Apple’s integrated development environment (or IDE) for both OS X and iOS development.

Create and Test a New Project

To get started developing your app, you create a new Xcode project.

To create a new project
  1. Launch Xcode (located in the Applications folder).

    If you’ve never created or opened a project in Xcode before, you should see a Welcome to Xcode window similar to this:

    image: ../Art/1_newproject.png

    If you’ve created or opened a project in Xcode before, you might see a project window instead of the Welcome to Xcode window.

  2. In the Welcome to Xcode window, click “Create a new Xcode project” (or choose File > New > Project).

    Xcode opens a new window and displays a dialog in which you choose a template. Xcode includes several built-in app templates that you can use to develop common styles of Mac apps.

    image: ../Art/2_templatedialog.png
  3. In the OS X section to the left of the dialog, select Application.

  4. In the main area of the dialog, select Cocoa Application and click Next.

    A new dialog appears that prompts you to name your app and choose additional options for your project.

    image: ../Art/3_projectsettingsdialog.png
  5. Choose the following options:

    • In the Product Name field, type TrackMix.

    • In the Company Identifier field, type the identifier for your company, or com.MyCompany.

    • In the App Store Category pop-up, choose None.

  6. Make sure that the Use Automatic Reference Counting option is selected and that the Create Document-Based Application (appears above Document Extension), Use Core Data, and Include Unit Tests options are unselected.

  7. Click Next.

    Another dialog appears that allows you to specify where to save your project.

  8. Specify a location for your project (make sure that the Source Control option is unselected) and then click Create.

    Xcode opens your new project in a window (called the workspace window), which should look similar to this:

    image: ../Art/4_projectwindow.png

Take a few moments to familiarize yourself with the workspace window that Xcode opens for you. You’ll use the buttons and areas identified in the window below throughout the rest of this tutorial.

image: ../Art/workspace_window_callouts.png

If the utilities area in your workspace window is already open (as it is in the window shown above), you can close it for now because you won’t need it until later in the tutorial. The rightmost View button controls the utilities area. When the utilities area is visible, the button looks like this: image: ../Art/utilites_button.jpg

If necessary, click the rightmost View button to close the utilities area.

Even though you haven’t yet written any code, you can build and run your app in Xcode.

To build and test the app
  1. Click the Run button in the Xcode toolbar (or choose Product > Run).

    If a dialog appears asking whether Xcode should enable developer mode on this Mac, click Disable.

    Xcode should build your project and launch the app. When your app starts up, it should have a standard menu bar and display a single window.

    image: ../Art/5a_trackmix_menu.png
    image: ../Art/5_buildandrun.png
  2. Test the app.

    You can move and resize the window. However, if you close the window, there is no way to get it back. You should also find that menus display when you click them, and if you choose TrackMix > About TrackMix, an About window is displayed.

  3. Quit the app by choosing TrackMix > Quit TrackMix.

    Don’t mistakenly choose the Quit command in Xcode, or you’ll quit Xcode. You can also click the Stop button in Xcode.

Right now, your app is not very interesting: it simply displays a blank window. To understand where the blank window comes from, you need to learn about the objects in your code and how they work together to start the app.

Find Out How an App Launches

Because you based your project on an Xcode template, much of the basic app environment is automatically set up when you run the app. For example, Xcode creates an app object which, among a few other things, establishes the run loop. (A run loop registers input sources and enables the delivery of input events to your app.) Most of this work is done by the NSApplicationMain function, which is supplied for you by the AppKit framework and is automatically called in your project’s main.m source file.

To look at the main.m source file
  1. Make sure the project navigator is open in the navigator area.

    The project navigator displays all the files in your project. If the project navigator is not open, click the leftmost button in the navigator selector bar:

    image: ../Art/6a_navigatorselector.png
  2. Open the Supporting Files folder in the project navigator by clicking the disclosure triangle next to it.

  3. Select main.m.

    Xcode opens the source file in the editor area of the window, which should look similar to this:

    image: ../Art/6_main_m.png

The call to the NSApplicationMain function creates an instance of the NSApplication class and an instance of the AppDelegate class, which is provided for you by the Cocoa Application template. In this tutorial, the singleton instance of this class is referred to as the app delegate. The main job of the app delegate is to provide a window you can access through its window property. The window object provides a container for the app’s visible content and helps deliver events to other app objects. The app delegate can also perform some app configuration tasks before the app is displayed. You add your custom behavior and logic to the AppDelegate class and any other classes you create.

The instance of the NSApplication class, called the app object, loads the main nib file when the app launches. Nib files are an archive of UI elements and other objects. The main nib file, MainMenu.xib, usually contains the parts of your user interface, such as the menu bar and window, that are visible the entire time your app is running. When a nib file is loaded, the objects it contains are instantiated.

To look at the nib file, and the window in the nib file
  1. Click MainMenu.xib under the TrackMix group in the project navigator.

    The file has the extension .xib but by convention it is referred to as a nib file. Xcode displays the file on a canvas in the editor area.

    If an outline view appears instead of the standard editor, click the Standard editor in the Editor toolbar.

    image: ../Art/8a_standardeditor.png
  2. To display the window, click the window icon in the sidebar.

    image: ../Art/8_mainwindow_xib.png

The sidebar contains several items split into two groups by a dividing line. Above the line are placeholders—objects that are not created as part of the nib file itself, but exist externally. Below the line are objects created as part of the nib file:


In this chapter you used Xcode to create a new project based on the Cocoa Application template and you built and ran the default app that the template defines. Then you looked at some of the basic pieces of the project, such as the main.m source file, and the nib file, and learned what objects are created and loaded from the nib file when the app launches.

In the next chapter, you’ll learn how to lay out and configure the user interface without writing any code.