Xcode 4 Differences for Chapter 3

Changes in Chapter 3, "All About Objects," include a few window and sheet layout changes, and require you to discover where a couple of configuration panels have been hidden.

The changes in these posts are divided by section headings, in the order these appear in the book.

Objects and Objective-C

There is no Classes group in an Xcode 4 template-generated project. Use the top-level TextApp group instead.

To add a new file, the New File… menu item is now in the first contextual menu that appears.

When creating a new class file, Xcode 4 will ask you to specify a “Subclass of”—make this NSObject (it’s probably been filled in for you):

Xcode 4 New Class File Subclass Sheet

The window shown in Figure 3.2 now looks like this:

Xcode 4 New File Location Sheet

Just type the name of the class (NotifyingClass), excluding the .m extension. There won’t be an Also create “NotifyingClass.h” checkbox in Xcode 4, but the .h file will automatically be created.

Once the files are created, they may end up listed in the Project Navigator pane at the very bottom of the TextApp group, i.e. under the Supporting Files group. This doesn’t matter, but if it bothers you, just click and drag them up underneath the MainMenu.xib file while they are both still selected:

Xcode 4 Project Window Showing New Class Files

Xcode 4 may display the NotifyingClass.m file first, rather than the NotifyingClass.h file. Just click either of the filenames in the list to show their contents.

Setting Up Our Class Description

You’ll find that the Xcode 4 file template for the .h file has the directive #import <Foundation/Foundation.h> rather than the #import <Cococa/Cocoa.h>. This doesn’t matter; either is fine, and in fact neither is necessary so the directive could be removed altogether.

Creating an Instance of Our Notifying Class

You only need to click the MainMenu.xib file (located in the TextApp group, not Resources) once to open it in the project window (double-clicking will open it in a new window, from which it’s hard to find where to locate the Library or Inspectors).

You can drag out and drop the blue Object cube anywhere in the graph paper area, or specifically at the bottom of the icons on the left hand side; either way, it will be displayed at the bottom of the icon list when you release the mouse button.

Xcode 4 Interface Editor Dragging Out an Object

Use View > Utilities > Identity Inspector (Opt-Cmd-3) to show the inspector panel:

Xcode 4 Object Inspector

Introducing NSLog

The Console has moved in Xcode from a separate window into an integrated Debug Area. Select View > Show Debug Area (Shift-Cmd-Y), and it will appear at the bottom of the main Xcode window. You’ll need to make sure you can see the Console part of this view, so check the segmented control highlighted below:

Xcode 4 Console in Debug Area

By default, Xcode 4 may hide the Debug Area whenever an application is run. Take a look at the General Overview post for information on changing this behavior.