Introduction

Welcome to Xcode 6 Start to Finish! This book will show you how to use Apple’s integrated development environment to make great products with the least effort.

Xcode 6 is the descendant of a family of development tools dating back more than 20 years to NeXT’s ProjectBuilder. It started as a text editor, a user-interface designer, and a front end for Unix development tools. It has become a sophisticated system for building applications and system software, with a multitude of features that leverage a comprehensive indexing system and subtle incremental parser to help you assemble the right code for your project, and get it right the first time.

That much power can be intimidating. My aim in Xcode 6 Start to Finish is to demystify Xcode, giving you a gradual tour through examples that show you how it is used day to day. Don’t let the gentle approach fool you: This book will lead you through the full, best-practices workflow of development with Xcode 6. There are no “advanced topics” here—I’ll show you version control and unit testing in their proper places in the development process.

How This Book Is Organized

First, a word on my overall plan. This is a book about developer tools. If it teaches you something about how to use the Cocoa frameworks, or something about programming, that’s fine, but that’s incidental to showing you the Xcode workflow. There are many excellent books and other resources for learning the frameworks; you’ll find many of them listed in Appendix B, “Resources.”

Every tour needs a pathway, and every lesson needs a story. The first three parts of this book demonstrate Xcode through three applications—a command-line tool, an iOS app, and an OS X application—that calculate and display some statistics in American football. None of the apps are very useful; the graphical apps run almost entirely on sample data. But they demand enough of the development tools to give you a solid insight into how to use them.

Xcode supports some technologies, like Core Data and OS X bindings, that are not for beginners. Xcode 6 Start to Finish dives straight into those techniques, ignoring conceptually simpler approaches, so I can demonstrate how Xcode works. Other “advanced” techniques, like unit testing and version control, appear at the points where best practices require them. This will be the workflow as Xcode supports it.

I’m using applications for iOS and OS X as examples, but read both Parts II and III, even if you’re only interested in one platform. The applications are only stories; the techniques apply to both platforms.

First Steps

In Part I, I’ll take you from installing Xcode and running your first project through basic debugging skills. You’ll work through a small command-line application. The application may be simple, but you’ll learn foundational skills you’ll need before adding the complexity of graphical apps.

Image Chapter 1, Getting Xcode—Some things to consider before you download Xcode 6; two ways to download and install it.

Image Chapter 2, Kicking the Tires—Your first look at Xcode, setting up a trivial project and running it.

Image Chapter 3, Simple Workflow and Passive Debugging—Write, build, and run a simple application, and respond to a crash.

Image Chapter 4, Active Debugging—Take charge of debugging by setting breakpoints and tracing through the program. I’ll show you how to organize your workspace.

Image Chapter 5, Compilation—A pause to describe the process of building an application.

Image Chapter 6, Adding a Library Target—Add a library target to a project, and learn how to build a product from multiple targets.

Image Chapter 7, Version Control—Why source control is important, and how to take advantage of Xcode’s built-in support for versioning through Git and Subversion.

The Life Cycle of an iOS Application

Part II tells the story of a small iPhone app, and how to use Apple’s developer tools to build it. It introduces you to the graphical editor for user interfaces, and shows how to profile an app to optimize its speed and memory burden.

Image Chapter 8, Starting an iOS Application—You’ll start by creating an iOS project, and learn the Model-View-Controller design at the core of Cocoa on iOS and OS X alike.

Image Chapter 9, An iOS Application: Model—Design a Core Data schema and supplement it with your own code.

Image Chapter 10, An iOS Application: Controller—Create a controller to link your model to the on-screen views. On the way, I’ll tell you about refactoring, and Xcode’s continual error-checking.

Image Chapter 11, Building a New View—Design the user-interface views for your app with the integrated Interface Builder, and take advantage of source-code completion.

Image Chapter 12, Auto Layout in a New View—In Xcode 6, Auto Layout is more about getting things done than fighting the tools. Learn how to make Cocoa layout do what you want.

Image Chapter 13, Adding Table Cells—While adding an in-screen component to your app, you’ll debug memory management, and control how Xcode builds, runs, and tests your apps through the Scheme editor.

Image Chapter 14, Adding an Editor—Add an editor view, and get deep into Storyboard.

Image Chapter 15, Unit Testing—Unit testing speeds development and makes your apps more reliable. I’ll show you how Xcode supports it as a first-class part of the development process.

Image Chapter 16, Measurement and Analysis—Use Instruments to track down performance and memory bugs.

Image Chapter 17, An iOS Extension—Create a system-wide extension and a shared library to bring your app’s value beyond its own screen.

Image Chapter 18, Provisioning—Behind the scenes, the process of getting Apple’s permission to put apps on devices is complicated and temperamental. I’ll show you how Xcode saves you from most of the pain, and give you a few tips on how to get out if it backs you into a corner.

Xcode for Mac OS X

Part III shifts focus to OS X development. Some concepts are more important to OS X than iOS, but you’ll be learning techniques you can use regardless of your platform.

Image Chapter 19, Starting an OS X Application—Carrying iOS components over to OS X; what the responder chain is, and how Interface Builder makes it easy to take advantage of it.

Image Chapter 20, Bindings: Wiring an OS X Application—As you build a popover window, you’ll use OS X bindings to simplify the link between your data and the screen. You’ll also encounter autosizing, a legacy technique for laying out view hierarchies.

Image Chapter 21, Localization—How you can translate your Mac and iOS apps into other languages.

Image Chapter 22, Bundles and Packages—You’ll master the fundamental structure of most Mac and iOS products, and how both platforms use the Info.plist file to fit apps into the operating system.

Image Chapter 23, Property Lists—Learn the basic JSON-like file type for storing data in both OS X and iOS.

Xcode Tasks

By this point in the book, you’ll have a foundation for digging into the details of the Xcode toolset. Part IV moves on to topics that deserve a more concentrated treatment than Parts II and III.

Image Chapter 24, Documentation in Xcode—How Xcode gives you both immediate help on API, and browsable details on the concepts of Cocoa development. Find out how you can add your own documentation to the system.

Image Chapter 25, The Xcode Build System—I’ll show you the fundamental rules and tools behind how Xcode goes from source files to executable products.

Image Chapter 26, Instruments—Using Apple’s timeline profiler, you can go beyond basic performance and memory diagnostics to a comprehensive look at how your program uses its resources.

Image Chapter 27, Debugging—How to use breakpoint actions and conditions to eliminate in-code diagnostics. You’ll also find a tutorial on the lldb debugger command set, for even closer control over your code.

Image Chapter 28, Snippets—A roundup of tips, traps, and features to help you get the most from the developer tools.

Appendixes

The appendixes in Part V contain references to help you master the build system, and find help and support.

Image Appendix A, Some Build Variables—The most important configuration and environment variables from Xcode’s build system.

Image Appendix B, Resources—A compendium of books, tools, and Internet resources to support your development efforts.

About Versions

This book was finished in the fall of 2014. Xcode 6 Start to Finish is written to early versions of 10.10, iOS 8.2, and Xcode 6.2.

About the Code

Xcode 6 Start to Finish has many examples of executable code—it’s about a system for creating code and running it. My goal is to teach workflow. What the code itself does is practically incidental. In particular, be aware: Much of the code in this book will not run as initially presented. Xcode 6 Start to Finish is about the development process, most of which (it seems) entails prosecuting and fixing bugs. You can’t learn the workflow unless you learn how to respond to bugs.

So I’ll be giving you buggy code. You may find it painful to read, and if you try to run it, it will be painful to run. Trust me: It’s for a reason.

Also, sample code for this book is available at informit.com/title/9780134052779 (register your book to gain access to the code). You’ll find archives of the projects in this book as they stand at the end of each chapter. With very few exceptions—I’ll make them very clear—if you want the project as it stands at the start of a chapter, you should use the archive for the end of the previous chapter.

The chapter archives do not include version-control metadata. If you are following along with the examples, and using Git (or Subversion) for your work, copy the changes into your own working directory. If you replace your directory with a sample directory, you’ll lose your version history.

Conventions

This book observes a number of typographic and verbal conventions.

Image Human-interface elements, such as menu items and button labels, are shown like this.

Image File names and programming constructs are shown like this. This will sometimes get tricky as when I refer to the product of the “Hello Worldproject (plain text, because it’s just a noun) as the file Hello World.

Image Text that you type in will be shown like this.

Image When I introduce a new term, I’ll call it out like this.

I’ll have you do some command-line work in the Terminal. Some of the content will be wider than this page, so I’ll follow the convention of breaking input lines with backslashes () at the ends. I’ll break long output lines simply by splitting them, and indenting the continuations. When that output includes long file paths, I’ll replace components with ellipses (. . . ), leaving the significant parts.

For its first 20 years, the Macintosh had a one-button mouse. (Don’t laugh—most purchasers didn’t know what a mouse was; try pushing the wrong button on an old Mac mouse.) Now it has four ways to effect an alternate mouse click: You can use the right button on an actual mouse (or the corner of the mouse where the right button would be); you can hold down the Control key and make an ordinary click; you can hold down two fingers while clicking on a multi-touch trackpad (increasingly common even on desktop Macs); or you can tap at a designated corner of a multi-touch trackpad. And there are more variations available through System Preferences. Unless the distinction really matters, I’m simply going to call it a “right-click” and let you sort it out for yourself.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.193.207