Introducing Xcode 4 X AL code is Apple’s free suite of developer tools; it is used to create applications for iOS mobile devices and for Mac OS X. Xcode 4, shown in Figure 1.1, is the most recent version and is a radical update with many new features. TE RI Developer tools are complex, and Xcode has always tried to hide much of that complexity from novice developers. You can use Xcode in a very simple click-to-build way, but this simplicity can be misleading.
4 Getting Started Figure 1.1 Xcode 4’s simplified interface hides familiar old features and some unexpected new ones. Understanding the History of Mac Development Tools Before OS X, Apple’s IDE (Integrated Development Environment) was MPW (Macintosh Programmer’s Workshop). As shown in Figure 1.2, MPW, which is still available today, was in competition with a commercial product called CodeWarrior.
Chapter 1: Introducing Xcode 4 5 Figure 1.2 The MPW IDE is available on Apple’s FTP site, and users of antique Macs can download and use it. NOTE Early versions of MPW were famous for their error messages, which included “We already did this function,” “This array has no size, and that’s bad,” and “Call me paranoid, but finding ‘/*’ inside this comment makes me suspicious.” Later Apple IDEs reverted to more traditional messages.
6 Getting Started Xcode 3.2 is shown in Figure 1.3 and was released with OS X 10.6 “Snow Leopard.” Prior to this release, Apple supplied separate builds of Xcode for iOS and OS X development. With version 3.2, Xcode became a unified development environment that could target both platforms. This widened the developer base, but also made Xcode more difficult to download. The Mac version was around 800GB. The combined version is typically around 3GB. Figure 1.
Chapter 1: Introducing Xcode 4 7 Alternatives to Xcode Xcode is optimized for visual development of Objective-C and Cocoa projects. In practice this means the Cocoa and Cocoa Touch libraries and documentation are tightly integrated into Xcode. Xcode 4 has moved toward improving support for C++, but there are still limits to how easily it’s possible to mix Objective-C, Objective-C++, and C++ code, Apple’s own libraries and example source code are a combination of traditional C and Objective-C.
8 Getting Started A code editor that includes static code checking, code completion, and dynamic hints and tips. A visual UI design tool called Interface Builder, also known as IB, which can prototype visual interfaces, but can also be used to manage and preload other application objects. Further integrated editors for class management and for Apple’s Core Data database framework. A debugger that supports expressions and conditional breakpoints.
Chapter 1: Introducing Xcode 4 9 NOTE Rumors surface regularly of a merger, or at least a relationship, between Xcode and Microsoft’s Visual Studio series of development tools. There would be obvious commercial benefits to allowing Windows developers access to iOS and the App Store, but Apple’s culture tends to be closed and proprietary. A formal link is possible, but at the time of writing it seems very unlikely.
10 Getting Started Support for Schemes, which offer fine control over how projects build, and support different build options for different applications (for example, testing, debugging, packaging for distribution, and so on) Support for Workspaces, which make it easy to manage and work on multiple related projects Backward compatibility with Xcode 3.
Chapter 1: Introducing Xcode 4 11 In the first release of Xcode 4, it’s no longer possible to customize this area with your own selection of build/run/stop/clean options, as it was in Xcode 3. Working with tabs Xcode 4 introduces tabs—editor sub-windows that work like the tabs in a browser, allowing single-click switching between selected files, as shown in Figure 1.4. Tabs replace the file list that appeared above the editor pane in Xcode 3.
12 Getting Started Working with multiple windows Not every developer is enthusiastic about single-window development. Fortunately, you can open multiple windows into a single project and select a different collection of editors and features in each window. A key goal is flexibility; you can arrange your workspace how you want it, with the features you want to see. As shown in Figure 1.5, you can still create a separate floating window to edit a single file by double-clicking the file. Figure 1.
Chapter 1: Introducing Xcode 4 13 Figure 1.6 The navigation bar drastically speeds up access to any file in your project, by presenting them all in a single unified menu tree. NOTE In beta versions of Xcode 4 you could use the menu tree to navigate to the methods in each file. This feature was removed in the final release. It was a very useful feature, so it may return in future updates. Symbols still appear in the navigation bar in a separate menu, much as they did in Xcode 3.
14 Getting Started Figure 1.7 At the left of the navigation bar, a separate menu shows files and items that are more loosely related to the currently selected file. Using the Assistant Xcode 3 included a counterpart file selector that switched an editor window between a class header and its corresponding implementation file. Xcode 4 introduces Assistant, which is designed to work with a new vertically split double-pane view.
Chapter 1: Introducing Xcode 4 15 Figure 1.8 The button for selecting the Assistant option is in the grouping at the top right and looks like a light bulb. It splits the editor into two panes and automatically displays a counterpart file whenever a file is selected. With the vertical split view and Assistant, you no longer need to manually switch between counterparts or to work with the less efficient horizontal split view available in Xcode 3.
16 Getting Started Figure 1.9 You can change the behavior of Assistant to select a specific type of counterpart file, which can include an object’s superclass as well as its headers and includes. This is useful for newcomers who may not be aware that Cocoa and other OS X headers are available in Xcode and can be used as a reference. Working with Interface Builder IB is now built into Xcode 4. It launches at the same time as Xcode, and you can edit a nib file simply by selecting it.
Chapter 1: Introducing Xcode 4 17 Figure 1.10 Creating outlet code automatically in Xcode 4. This is a very powerful time-saving feature. Exploring code and file management Xcode 4 includes two new panes at the left and the right that can be revealed or hidden as needed, using a pair of buttons near the top right of the toolbar. As shown in Figure 1.11, the left pane, known as the navigation pane, includes a simplified but familiar version of the Groups & Files pane from Xcode 3.
18 Getting Started Figure 1.11 New left and right panes in Xcode 4 display ancillary information and manage optional features that may not be needed while editing. The utilities pane is also shown in Figure 1.11. It includes a new Library sub-pane that can display file templates, standard code snippets, standard system objects that include both UI and data classes, and project media files. The Code Snippet feature in the Library is shown in Figure 1.12.
Chapter 1: Introducing Xcode 4 19 Figure 1.12 The new Code Snippets feature makes it easy to reuse code and is a partial replacement for Xcode 3’s Code Sense macros. Exploring the debugger As shown in Figure 1.13, the debugger now appears in a new pane at the bottom of the editor window. To reveal it, select View ➪ Show Debugger Area. Both console output and debugger output appear in this area. You can choose to view either or both by clicking the new buttons that appear at the top right of the area.
20 Getting Started Figure 1.13 The new debugger area no longer appears in a separate window, although for convenience you may decide to launch it in one. On a smaller monitor, the debugging and console area can feel cramped. Comparing iOS and OS X Development Although Xcode supports OS X and iOS development equally and it can be used to develop apps for both the iOS and Mac App Stores, there are significant differences between the two platforms.
Chapter 1: Introducing Xcode 4 21 NOTE Xcode doesn’t include network deployment features. But it does create application binaries that can be handed to network deployment tools. Earlier versions of Xcode supported universal binary development, which was backwardcompatible with PowerPC hardware. Although OS X 10.6 Snow Leopard was the first Intel-only version of OS X, Xcode supports universal binaries for Mac development and can still be used to develop applications for PowerPC targets.
22 Getting Started Developing for iOS iOS development is more complicated than OS X development. Development is controlled by provisioning, an Apple-generated security control, which is built into Xcode and manages access to hardware testing and App Store distribution. iPhone, iPod touch, and iPad platforms all use iOS, but these platforms are significantly different and may not always run the same version of iOS.
Chapter 1: Introducing Xcode 4 23 Figure 1.15 Create a very simple iOS app, and test it in the Simulator. The Simulator is best considered an educational rather than a production environment. It’s adequate for apps with simple text and graphics, but it doesn’t fully implement the GPS, accelerometer, gyroscope, or other hardware options in iOS devices. OS X and iOS cross-development In theory, you can migrate projects between platforms.
24 Getting Started The development workflow is almost completely distinct. The two platforms have these features: A separate collection of classes for UI design and for data management: Many of the more creative and sophisticated classes in OS X are either absent or only partially implemented in iOS. A separate testing and debugging environment: iOS applications can run in a Simulator or on a hardware device. OS X applications run in a debugging sandbox.