- Creating New Projects
- Building Hello World the Template Way
- Using the Simulator
- The Minimalist Hello World
- Converting Interface Builder Files to Their Objective-C Equivalents
- Using the Debugger
- Memory Management
- Recipe: Using Instruments to Detect Leaks
- Recipe: Using Instruments to Monitor Cached Object Allocations
- Analyzing Your Code
- Building for the iOS Device
- Detecting Simulator Builds with Compile-Time Checks
- Performing Runtime Compatibility Checks
- Pragma Marks
- Preparing for Distribution
- Over-the-Air Ad Hoc Distribution
- Submitting to the App Store
Xcode helps you craft iOS SDK applications with an exciting suite of code editors and testing tools. This chapter introduces you to the basics of using Xcode to build your projects. You see how to build a simple Hello World project, compile and test it in the simulator, and then learn how to compile for and deploy to the device. You also discover some basic debugging tools and walk through their use as well as pick up some tips about handy compiler directives. This chapter also looks at how to submit to the App Store and perform ad hoc distribution for testing. By the time you finish this chapter, you’ll have followed the application-creation process from start to finish and been shown valuable tricks along the way.
Creating New Projects
If diving into SDK programming without a lifeline seems daunting, be reassured. Xcode simplifies the process of getting started. It provides preconfigured projects that you can easily adapt while exploring the SDK. These projects provide fully working skeletons. All you need to do is add a little custom functionality to make that app your own.
To get started, launch Xcode 4 and choose File > New Project (Command-Shift-N). The New Project template window (see Figure 3-1) opens, allowing you to select one of these application styles to get started. These project styles are chosen to match the most common development patterns for iOS. Your choices are as follows:
- Document-Based Application—Intended for use with iCloud, the document template creates a starting point for building applications around ubiquitous elements.
- Master-Detail Application—Usually based around lists and tables, master-detail applications let users drill their way through a hierarchical interface. These apps offer a tree-structured collection of interface choices, each choice sliding to a new screen or presenting, in the case of the iPad, in a separate detail view. The bars at the top of the navigation screens include an integrated Back button, letting users return to previous screens with a single tap. On the iPad, split views automatically accommodate themselves to match device orientations. In landscape mode, both views are shown at once; in portrait, the detail view is shown and the selection choices appear via a navigation-bar-based popover.
- OpenGL Game—When programming with OpenGL ES, all you need is a view to draw into and a timer that offers an animation heartbeat. The OpenGL Game template provides these elements, letting you build your OpenGL ES graphics on top.
- Page-Based Application—Create a book-style application by choosing this page view controller-based template. New to iOS 5, the page view controller allows users to navigate through an electronic “book” using familiar touch-based gestures. The data source client feeds view controllers to the application, and a delegate allows the app to respond to gesture-based navigation and orientation updates.
- Single View Application—This simple template provides a basic starting point for a primary view controller, offering storyboards for both iPhone and iPad distribution. Choose this style when you’re looking for an app that centers on a primary view rather than one that needs a specialized container style, such as a navigation controller, tab bar controller, split view controller, page view controller, and so on.
- Tabbed Application—Apple’s iPod and YouTube applications offer typical examples of tab bar applications. In these applications, users can choose from a series of parallel screens by tapping buttons in a bar at the bottom of the application. For example, the YouTube application lets you choose from Featured Videos, Most Viewed, Bookmarks, and the search pane, each of which is accessed through a tab button. The Tabbed Application template provides a skeleton that you can grow to add panes and their contents. Although you can select either the iPhone or iPad as your target product in Xcode, Apple encourages you to avoid creating tab-bar-style applications on the iPad. The iPad’s generous screen space provides enough room that you do not need to fold your main interfaces using the conventions of tab bar and navigation applications.
- Utility Application—Meant to be the simplest style of application, the Utility Application template creates a two-sided single-view presentation like the ones you see in the Stocks and Weather application. The template provides a main view and a flip view, which you can easily customize. This application template uses a simple flip-to-the-other-side presentation on the iPhone. On the iPad, it offers a popover linked to an information bar button item. Utility applications work best when they are highly focused. The flip-view or popover generally serves for in-app settings rather than an extension of the primary interface feature set.
- Empty Application—The window-based application essentially offers the same template as the Single View one but without the storyboards. You get an application delegate and a customizable window, and that’s about it. One advantage of choosing this template is that it’s relatively easy to customize if you prefer to build your iPhone applications completely from scratch.
Figure 3-1. The Xcode New Project template selection window. The Xcode interface will change as Apple continues evolving its design tools.