31,90 €
The essential skills and technologies needed for iOS developmentin one handy guide!The unprecedented popularity of iOS devices, such as the iPhone,iPad, and iPod touch, has led to a development boom. Ifyou're eager to become part of the action, then this is thebook for you! Packed with must-have information on iOS development,this handy guide covers Objective-C, Xcode, Frameworks, and sounddesign principles and explains how to upload an app to the appstore and integrate apps with the latest advances that Apple offersdevelopers. The featured tips and tricks will get you up andrunning and sharpen your skills as an iOS developer.* Gets savvy beginning developers started with iOS developmentwhile also keeping experienced iOS developers up to date on thelatest in this field* Features easy-to-follow instructions on the strong and stableiOS platformiOS Development Portable Genius covers all the essentialsyou need to get started with iOS development today.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 419
Veröffentlichungsjahr: 2012
Table of Contents
Chapter 1: How Can I Start Developing for iOS?
Getting Started with App Development
Choosing a Mac
Choosing a processor
Selecting memory
Selecting a monitor
Selecting other peripherals
Selecting a form factor
Joining the iOS Developer Program
Understanding enrollment options
Enrolling in the iOS Developer Program
Downloading and Installing Xcode
Understanding SDKs and betas
Installing Xcode from the App Store
Installing Xcode from a developer download
Understanding other installation requirements
Chapter 2: How Do I Get Started with Xcode?
Understanding Xcode
Introducing Xcode’s User Interface
Introducing the main Xcode window
Viewing and hiding UI features
Using the other toolbar features
Introducing the Navigator area
Using the Project navigator
Introducing the Editor area
Introducing iOS and the Apple Documentation
Understanding Resource Types
Understanding Topics
Understanding frameworks and layers
Using the documentation browser
Accessing the documentation
Getting Further Help
Putting It All Together
Chapter 3: How Do I Build and Run an Application?
Building Applications
Creating a new project
Building a project
Working with the Simulator
Understanding Xcode’s Project Templates
Creating iPhone, iPad, and Universal projects
Exploring the app templates
Customizing and expanding templates
Building Apps from Sample Code
Building sample projects from the documentation
Building sample projects from other sources
Building Apps for Test Devices
Understanding certificates and provisioning
Creating certificates and provisioning profiles
Using devices for testing
Chapter 4: What Are Applications Made Of?
Understanding Applications
Understanding messages
Using messages in practice
Understanding code
Understanding messages in objects
Building apps from messages
Understanding App Structure
Understanding message timing
Working with message timing
Introducing Views, Nib Files, and Storyboards
Looking at nib files
Adding objects to a UI
Understanding the view hierarchy
Modifying views and the view hierarchy
Understanding Views and Controllers
Introducing storyboards
Introducing Model-View-Controller (MVC)
Using MVC
Working with MVC messages
Appreciating Graphic Design
Summarizing UI Creation
Chapter 5: How Do I Create Code?
Introducing Code Design
Organizing data
Mixing C and Objective-C
Editing and Building Code
Understanding Errors and Warnings
Understanding compile-time errors
Understanding warnings
Understanding run-time errors
Understanding the C Language
Understanding computers
Representing data in C
Creating a Simple App in C
Adding code
Managing data
Grouping data
Making decisions
Repeating code
Re-using code with functions
Understanding scope
Using other C idioms
Chapter 6: How Do I Use Objects in My Code?
Moving from C to Objective-C
Thinking with objects
Understanding classes
Understanding inheritance
Exploring messaging and behaviors
Introducing Objective-C Code
Working with messages and properties
Creating objects
Defining Classes in Your App
Using premade subclasses
Adding your own subclasses
Using subclassing
Exploring touch messages
Getting started
Going Deeper with Objective-C
Introducing selectors
Using Target-Action
Getting started with delegates and protocols
Class methods
Chapter 7: How Can I Use Objects to Manage Data and Schedule Events?
Managing Text with NSString
Creating a string
Comparing strings
Managing Data Collections
Understanding mutable collections
Understanding “objectification”
Understanding key-value coding (KVC)
Using NSSet
Processing objects in collections
Key-value observing (KVO)
Scheduling Events
Creating a simple delay
Creating a simple timer
Scheduling an event at a future time
Chapter 8: How Do I Handle Input from the User?
Understanding User Interaction
Introducing actions, outlets, and responder events
Working with actions, outlets, and responder events
Working with Action Messages
Working with action messages in IB
Editing action connections
Creating and Using Outlets
Creating an outlet
Using an outlet
Using the Responder System
Working with a text field
Working with touch events
Working with single touch events
Working with multi-touch
Introducing gestures
Working with gesture recognizers
Subclassing in IB
Chapter 9: What Are Frameworks and How Do I Use Them?
Understanding Frameworks
Understanding iOS frameworks
Introducing third-party frameworks
Adding an iOS Framework to a Project
Finding the framework you need
Adding a framework to a project
Including framework header files
Adding objects from a framework to your project
Understanding Delegates and Protocols
Understanding delegates
Using delegates and protocols
Adding a Third-Party Framework to a Project
Chapter 10: How Do I Add Custom Graphics to My App?
Understanding UI Design
Creating an excellent UI
Designing a UI step by step
Sourcing Custom Graphics
Finding clip art and icons
Creating art manually
Paying a graphic designer
Using Custom Graphics
Adding a media file to your project
Creating a customized app background
Customizing controls
Creating icons and splash screens
Working with fonts
Drawing Graphics with Code
Using paths, strokes, and fills
Creating views and controls with code
Swapping Screens
Adding a modal screen
Creating more complex screen swaps
Using a storyboard
Managing Rotation
Controlling rotation
Controlling object layout
Adding Animations
Understanding animation technologies in iOS
Creating a UIView animation
Chapter 11: How Do I Add Other Standard App Features?
Multitasking
Setting up task switching
Working with event notifications
Using threads
Using blocks
Managing Memory
Understanding manual memory management
Using ARC with Objective-C code
Working with Files
Playing Sounds and Videos
Playing a sound with AVAudioPlayer
Connecting to the Internet
Checking for a connection
Using APIs
Creating Preferences
Adding and editing a Settings Bundle
Registering preferences
Accessing and setting values
Localizing Apps
Creating Localized.strings
Using Localized.strings
Creating localized nib files
Chapter 12: How Do I Test and Fix My App?
Testing Apps
User-testing your app
Introducing test builds
Getting started with debugging
Using the Xcode Debugger
Adding a breakpoint
Stepping through code
Viewing objects, variables, and memory
Creating conditional breakpoints
Deleting, listing, and editing breakpoints
Getting Started with Instruments
Running Instruments
Understanding the Allocations list
Chapter 13: How Do I Distribute Apps for Sale and Testing?
Understanding App Distribution
Introducing digital identities
Getting started with distribution profiles
Creating a Digital Identity
Generating a certificate signing request
Installing the certificates
Creating an App ID
Understanding app IDs
Using reverse domain names
Creating a matching bundle ID
Adding Test Devices
Finding a device UDID
Adding a device UDID
Creating and Installing Distribution Profiles
Creating a distribution profile
Installing distribution profiles
Creating an Ad Hoc Build
Setting the Deployment Target
Creating an Ad Hoc archive
Distributing an Ad Hoc app for testing
Uploading to the App Store
Creating support materials
Building and distributing to the App Store
Appendix A: C Cheat Sheet
iOS App Development Portable Genius
Richard Wentk
iOS App Development Portable Genius
Published byJohn Wiley & Sons, Inc.10475 Crosspoint Blvd.Indianapolis, IN 46256www.wiley.com
Copyright © 2012 by John Wiley & Sons, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-1-118-32989-4
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, 201-748-6011, fax 201-748-6008, or online at http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization of Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read.
For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at (877) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.
John Wiley & Sons, Inc. also publishes its books in a variety of electronic formats and by print-on-demand. Some content that appears in standard print versions of this book may not be available in other formats. For more information about Wiley products, visit us at www.wiley.com.
Library of Congress Control Number is available from the Publisher.
Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates in the United States and/or other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.
About the Author
Richard Wentk covers Apple products and developments for Macworld and MacFormat magazines and also writes about technology, creativity, and business strategy for titles such as Computer Arts and Computer Music. As a trainer and a professional Apple developer, he has more than 15 years of experience making complicated technology simple for experts and beginners alike. He lives online but also has a home in Wiltshire, England. For details of apps and other book projects, visit www.zettaboom.com.
Credits
Acquisitions Editor
Aaron Black
Project Editor
Martin V. Minner
Technical Editor
Brad Miller
Copy Editor
Gwenette Gaddis
Editorial Director
Robyn Siesky
Business Manager
Amy Knies
Senior Marketing Manager
Sandy Smith
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Barry Pruett
Project Coordinator
Katie Crocker
Graphics and Production Specialists
Joyce Haughey Andrea Hornberger
Proofreading and Indexing
BIM Indexing & Proofreading Services Potomac Indexing, LLC
For Annette.
“The best way to predict the future is to invent it”—Alan Kay
Acknowledgments
Although this book has my name on the cover, all books are a team effort. I’d like to thank acquisitions editor Aaron Black for getting the project started and project editor Martin V. Minner for support and good humor. Sincere thanks are also due to the rest of the team at Wiley for their hard work behind the scenes, especially copy editor Gwenette Gaddis and technical editor Brad Miller.
Personal gratitude to Annette, Hilary, Alexa, Michael, and the ET Tribe for keeping me informed, educated, entertained, and—not infrequently—fed.
iOS software development is also a team effort. The days of the solo developer working in isolation are long gone. There are too many indirect contributors to this book to list them all, but my sincere gratitude goes to all of them for sharing their time and skills so freely.
Finally, thanks as ever to Team HGA for making it all possible.
Introduction
Why develop your own apps? Because you can! Almost anyone with a Mac can get started making his own apps, as many people with little or no experience have already found out for themselves.
The benefits are obvious. Instead of relying on third-party apps in the App Store, you can create the apps you want using your own ideas and designs. For example, you can:
Create custom apps for friends and family. For example, you may want to share information or send messages privately.
Create applications for your business. If you travel, you can create an app that collects data onsite and sends it back to your main office.
Experiment with creative ideas for music, video, photography, and design.
Explore and invent new games.
The challenges are obvious too. As a beginner, getting started with app development is easy. But mastering the skills you need for more complex apps will take you longer.
This book gives you a good grounding in the basic features of iOS, but a detailed introduction to every feature would need an entire shelf of books. Fortunately, learning how to learn is a key developer skill. This book explains how to get the information you need from the two main sources of help—the official Apple documentation and the online forums and blogs, where you’ll find a truly vast collection of worked examples and informal professional support.
After a couple of finished apps, you may even find that you can improve your chances in the job market. Professional developers are highly sought after and can be very well paid. Although some developers have years of programming experience, others are hired on the basis of a couple of successful submissions to the App Store.
Most of all, app development can be satisfying and enjoyable. After you’ve tried it, you’ll be hooked—and you’ll soon be able to use your new skills for fun, entertainment, and profit.
Chapter 1: How Can I Start Developing for iOS?
App development relies on a single unified development tool called Xcode. Xcode is free for the curious, but experienced and dedicated developers can get advanced information about updates to iOS by paying a small annual fee to enroll in Apple’s iOS Developer Program. This chapter explains how to install Xcode, how to enroll as a developer, why you need lots of bandwidth for downloads, and why sometimes you’ll have more than one version of Xcode installed at the same time.
Getting Started with App Development
Choosing a Mac
Joining the iOS Developer Program
Downloading and Installing Xcode
Getting Started with App Development
iOS development doesn’t have to be expensive. In fact, you need only two tools to develop iOS apps:
A recent Mac. Although you can use any recent Mac, some models and specifications are more productive than others. You can find more details later in this chapter.
A copy of Xcode. Xcode, shown in Figure 1.1, is Apple’s app development toolkit. It has much in common with a standard Mac application, but it has some unusual extra features you’ll learn about later in this book. Xcode is available free from the Mac App Store.
1.1 Xcode is a big, complex, powerful application with many features. Fortunately, you don’t need to master everything it does to develop apps successfully.
Two further assets are optional, but very useful:
An iOS device. You might expect this to be essential, but it isn’t. Xcode includes the Simulator—a tool that can run and test iOS apps in an OS X mockup of either an iPhone, shown in Figure 1.2, or an iPad.
1.2 The Simulator built into Xcode can run iOS software, but its features are limited, and it isn’t a substitute for testing apps on real devices.
Membership in the iOS Development Program. This program for dedicated developers costs $99 a year.
Although membership in the iOS Development Program is optional, it offers important benefits:
Pre-release (beta) versions of iOS. Apple often makes the latest versions of iOS available to developers before they’re released to the public. This option also gives developers time to make new apps ready for sale as soon as the new version of iOS is released to the public or to modify existing apps to fix possible incompatibilities.
The latest versions of Xcode. Similarly, Apple makes new versions of Xcode available to developers before they’re released to the public.
Live device testing. Only members of the iOS Development Program can test their apps on real devices. The Xcode Simulator is adequate for basic testing, but it has significant limitations, so this is an essential option for dedicated developers.
Access to help and support information. This includes developer forums, and developer support videos, some of which are taken from the WWDC (World Wide Developer Conference) of the previous year.
Access to the App Store. Only members of the iOS Development Program can sell apps through the App Store.
Xcode can be used to develop both iOS and OS X applications. OS X developers have a separate paid-for program that gives access to the OS X App Store. But because you don’t need special hardware to test OS X apps, you can create and test OS X apps with Xcode before you sign up as an OS X developer.
Choosing a Mac
Although you can use any recent Mac for iOS development, not all Macs are equally productive. If you are developing for fun or curiosity, this may not matter to you, but it’s useful to understand the benefits and limitations of each possible choice.
Choosing a processor
Processor speed affects development times, but speed isn’t as critical as it is for high-performance applications such as gaming and video editing. Most iOS apps are small and simple, and Xcode doesn’t take long to convert your raw instructions—known as source code—into a working application.
In Xcode, this process is called building an application.
Currently, Xcode runs on OS X Lion, so at a minimum your Mac must have a Core 2 Duo series processor with 64-bit addressing and two cores. An i-Series processor may give better performance, depending on clock speed and number of cores. But using more cores won’t make a huge difference to your productivity, especially when starting out. There’s no need to invest in an expensive multi-core MacPro, at least not until you’re earning enough from your apps to justify spending your development budget on one.
Older versions of Xcode that work under Snow Leopard can be found online. If your Mac can’t run OS X Lion, you can experiment with these, but you won’t be able to use them to submit apps to the App Store.
Selecting memory
Xcode is a large application. If you’re dedicating a Mac to development, it will run comfortably in 4GB. But if you plan to have multiple windows open in Safari or some other web browser (a good way to read Xcode’s help files and documentation), you can easily run out of space with 4GB, as shown in Figure 1.3. A more realistic minimum is 8GB.
If you have too little memory, your Mac will stall for a minute or two every time you switch applications. If you plan to run Xcode, a browser, Mail, and perhaps some other applications simultaneously, you can avoid these distracting waits by expanding your Mac’s RAM to 8GB.
1.3 This Mac is running Xcode and the Chrome web browser. It has just 14.2MB of free RAM, guaranteeing a long wait when swapping between applications.
You can check how much memory applications are using, and how much memory is free, by running the Activity Monitor utility in /Applications/Utilities.
Selecting a monitor
Monitor size has a direct and immediate influence on productivity in Xcode. The larger your monitor, the more windows you can have open simultaneously, and the less time you’ll waste opening, closing, moving, and scrolling between various windows and panes.
When you use Xcode, you’ll spend more time editing, searching the web, and typing than you will building. You may also need to run supporting software, including sound, image, and perhaps video editing tools, at the same time as Xcode.
When starting out, expect to spend lots of time searching and reading the Xcode documentation. The more information you can view at once, the more easily you can make sense of what you’re learning.
So in practice, you’ll be significantly more productive with a large monitor—even a relatively cheap, non-Apple monitor—than with a small one.
Another option is to use multiple affordable 22-inch or 24-inch monitors simultaneously. Two monitors will be more productive than one, and if you can resurrect an old PC or Mac to use as a documentation browser, three or more monitors will help you work even more efficiently.
Selecting other peripherals
Printing out code—the instructions that make up an app—is often seen as an old-fashioned memory aid. But it can be surprisingly helpful, because it can be difficult to hold the entire structure of an app in (human) memory at the same time.
The other essential peripheral is a backup device. Any external hard drive will do for backups. You can simply copy project folders to the hard drive as you go, or you can rely on Time Machine to automate backups for you.
You can also speed up development significantly by using an SSD (Solid State Drive)—a very fast hard drive with no moving parts. Many Mac models support SSD as an option. It’s often possible to add an SSD to an existing Mac, although the cost is high compared to a standard hard drive, drive capacities are usually lower, and the upgrade can be physically difficult.
Code backups are not optional. If you have apps for sale, losing the source code for them can be a disaster.
Experienced developers keep their code online in a repository—a web site that stores code safely and manages versions. Optionally, you can set up a repository to share your code with other developers so they can contribute to your projects. There’s more information about this in Chapter 13.
Selecting a form factor
The physical size and configuration of your Mac has a direct influence on how easily and quickly you master app development. Although portable development is tempting, a permanent workstation is always more productive.
Running Xcode on a laptop
You can run Xcode on a laptop, including the MacBook Air models shown in Figure 1.4. This can seem an appealing option, but the small screen and relatively slow processor will slow down development. Most developers find they’re most productive in a quiet environment or one with customizable music and sound. Coffee shops and other public locations aren’t ideal. However, a MacBook Air or MacBook Pro can be useful to demonstrate app development in business meetings.
1.4 Portable development with a laptop can seem attractive, but it’s rarely as productive as working in a fixed location with a bank of large monitors.
Running Xcode on an iMac
An iMac, shown in Figure 1.5 is a good choice for development. It’s relatively affordable, easy to work with, includes a monitor, and can be expanded with further displays. You’ll find large-screen iMacs particularly productive. Make sure you use a model with at least 4GB of memory, but consider expanding it to 8GB if you can, especially if the iMac is your family’s main computer and it’s used regularly for other tasks.
1.5 An iMac can be an ideal development machine.
Running Xcode on a Mac Pro
As the name suggests, Apple’s Mac Pro line is aimed at professional Mac users. There’s no reason not to use a Mac Pro, shown in Figure 1.6, if you have access to one. But keep in mind the memory and processor requirements of Xcode and the fact that monitor size has more influence on development speed than raw processor power. It’s likely you’ll waste most of the power of a Mac Pro unless you pair it with two or more large monitors.
1.6 A Mac Pro is a good choice for professional developers with large budgets, but it’s excessive for beginners.
Running Xcode on a Mac Mini
The Mac Mini, shown in Figure 1.7, is a small and convenient solution for small office and home use. Mac Mini models aren’t outstandingly powerful, but they’re small enough to be unobtrusive, and they can easily be paired with two monitors. Most models have 2GB or 4GB of RAM; consider expanding this for dedicated development.
It’s well known among developers that the cheapest way to expand a Mac’s memory is to use third-party memory products. They’re significantly cheaper than Apple’s own memory, but offer identical performance. If you want to do the job yourself, Apple’s support web pages include detailed specifications and instructions. For example, http://support.apple.com/kb/ht1423 includes information about expanding the memory of an iMac.
1.7 A Mac Mini is ideal for light and medium performance applications, but may struggle as a professional web server for e-commerce.
Joining the iOS Developer Program
Enrollment is optional for casual developers who are experimenting with iOS, but essential for more dedicated developers who want to test apps on real iOS devices and also want access to the App Store.
Understanding enrollment options
There are two enrollment options. The $99 annual fee is the same for both, but they have different benefits:
Individual. For this option, you need an existing Apple ID, although it can be useful to create a new one even if you already have one, because there are occasional incompatibilities between developer and public Apple IDs. Individual enrollment is usually completed within 48 hours. Personal ID is confirmed via your credit card details.
Company. Enrolling as a company is more complex. In addition to an Apple ID, you’ll also be asked to provide proof of incorporation, with a valid address. The company name must be legally registered: Trade names aren’t allowed. Business enrollment can take up to two weeks, although it’s usually completed more quickly.
Individual developers have simplified access to the provisioning process used to manage test devices. As an individual, you work as a team of one and all possible team roles are available to you.
This is a benefit when getting started, but may become a limitation if your apps become very successful and you try to hire other developers to help you.
Support for team development is available only for company enrollment. A designated team leader can add or remove team members. He or she can also limit access to test devices and control which members are allowed to upload finished apps to the App Store.
Each option has legal and financial implications as well. If you enroll as an individual, Apple pays you as an individual. This may affect your tax status. Some countries, especially the U.S., withhold a percentage of the earnings of foreign developers unless they apply for them to be released. This process can take between three months and a year to complete.
If you enroll as a company, you are taxed as a company, which is usually simpler and more direct.
To summarize, if you already have a company, the extra wait at the start of the development process is a relatively small price to pay for the extra team options and the simpler financial processing.
If you don’t have a company or you have no need for team development, individual enrollment is a simpler option. It may cause issues later if your apps become very successful, but few app developers reach the stage where team development becomes necessary.
Enrolling in the iOS Developer Program
For individuals, enrollment isn’t a complicated process. To begin, open a web browser and navigate to https://developer.apple.com/programs/ios, shown in Figure 1.8.
1.8 The iOS Developer Program sign-up page.
Click the Enroll Now button, and work your way through the questions. You’ll be asked for your Apple ID, name, address, e-mail, nationality, and other basic information. Once enrollment is complete and you pay the enrollment fee, you’ll receive confirmation within 24 hours— although the confirmation e-mail usually arrives more quickly. You can then access the Developer Program features.
For companies, the process is similar, but you’ll be asked to confirm details of incorporation, usually by faxing a copy of your documents to Apple’s HQ in Cupertino. Company applications are checked manually, so the process takes longer. You may also be contacted by an Apple representative with some basic questions. Once enrollment is complete, you can access the Program features, but your account is set up with the extra team management features that aren’t offered to individuals.
Apple offers a separate Enterprise Program for large corporations that want to develop apps in-house and distribute them internally. Details are outside the scope of this book, but you can find the latest information at http://developer.apple.com/programs/ios/enterprise.
Will apps make me rich?
Realistically, it’s unlikely that app sales will make you rich. iOS apps continue to be more successful than apps for any other platform, including Android. But the iOS app store is heavily saturated, and many users already have more apps than they want or need.
App sales are heavily concentrated among a small number of super-sellers, who can be extremely successful. A slightly larger number of app developers make four or five figures a year, especially if they combine app sales with ad revenue captured from Apple’s iAD program. But many sellers are lucky to break even.
A successful app has four ingredients: a genuinely original idea or a popular existing idea; aggressive marketing, which may include a sizeable marketing budget; impressive graphic design; and a certain amount of luck. If you can adapt your apps for novel markets—for example, relatively few apps are written for the Chinese market—you can increase your chances of financial success.
However, at the time of writing, app developer skills are very much in demand among employers. While you may not be able to make a fortune selling your apps directly, you’ll certainly be able to increase your employability. Some developer compensation packages are very generous, so it’s well worth investigating this career option.
Downloading and Installing Xcode
The App Store and Developer Program versions of Xcode are different—sometimes significantly different—and they’re installed in different ways. Before you get started with downloading and installation, let’s look at a critical element of Xcode, the SDK (Software Development Kit).
Xcode is a continual work in progress. The versions of iOS it supports change with almost every release, but Apple also varies key features without notice, and delivery and installation options also change. The information that follows is valid for the public release of Xcode 4.3 for iOS 5.1. Don’t be surprised if some of the details have changed again by the time you read this.
Understanding SDKs and betas
Xcode has two main components. The current toolset includes the tools you use to edit, build, test, and distribute apps. Xcode is a fairly mature application now, so these tools change relatively slowly.
As iOS develops, new features are added and old features become obsolete. The other component in Xcode is called the SDK(Software Development Kit), and it manages this information.
Internally, the SDK is a collection of files and supporting documentation that defines all the features in a single version of iOS. Whenever iOS is updated, Apple releases a new version of Xcode with an updated SDK.
This seems simple, but there are complications. Basically, Xcode is always available in two versions:
The public version in the App Store includes the SDK for the most recent public version of iOS.
The Developer Program version usually includes the SDK for the next version of iOS. This version is a work in progress. It includes provisional features that may change before the final release.
A critical fact is that the Developer Program version goes through multiple updates. Each update is called a beta or preview, and is available for a period that can vary between a week and a month. When a new beta version is released, it replaces the previous preview, which becomes obsolete.
Just before a final public release, Apple announces a special version called a Release Candidate (RC) version. Unlike earlier previews, the RC version can usually be used to submit apps with the new features to the App Store. Occasionally, the RC version goes through one or two further updates to fix last-minute issues. More typically, it’s released “as is” after a couple of weeks. This gives developers a chance to submit compatible apps to the App Store and gives Apple time to review them.
Table 1.1 summarizes the process.
It would make sense for Apple to make each SDK update downloadable as a separate small file that could be installed in Xcode. Unfortunately, Apple doesn’t do this. Whenever the SDK is updated, you have to download a complete new version of Xcode.
Occasionally, Apple makes major changes to Xcode to update its editors and build tools. The last time this happened (in 2011), Xcode went through its own set of beta preview versions. Instead of an RC version, Apple eventually released a version called a GM (Gold Master) Seed. This process may happen again during the lifetime of this book.
Installing Xcode from the App Store
To install the current public version of Xcode from the Mac App Store, follow these steps:
1. Launch the App Store application on your Mac.
2. Type Xcode into the search box at the top right, as shown in Figure 1.9.
3. Click the Free button.
4. Wait while the App Store downloads an extremely large file.
1.9 You can get Xcode for free in the Mac App Store, but beware of the download size!
5. After the download completes, the App Store installs Xcode in /Applications, as shown in Figure 1.10.
Xcode is currently 3.4GB. This is a big, big download, and if you don’t have fast broadband, you’ll probably need to leave it running overnight. If you don’t have broadband at all, you won’t be able to download it directly. If you have a laptop, it can be worth visiting a local WiFi hotspot with good connectivity, such as an Internet café, and downloading Xcode there. (Not all café owners appreciate very large downloads, so it’s polite to check that this is okay before you start!)
6. Double-click Xcode to launch it. For convenience, you can also drag the application icon to your Dock.
1.10 The App Store downloads a separate installer and copies it into /Applications.
Installing Xcode from a developer download
Many developers find the App Store process inconvenient. From version 4.3, Apple rolled the complete Xcode package into a single, giant application that includes Xcode itself and assorted other tools you’ll meet briefly later in this book.
The giant application is bundled into a single .dmg file. Installation is much simpler than it was: You simply mount the .dmg file in Finder and drag a single Xcode application file to a folder of your choice.
It’s not yet clear if Apple is reserving this new installation method for developers or if future public App Store versions will work the same way. Whatever the outcome, the following steps summarize this alternative installation process:
You must be enrolled in the iOS Developer Program to access the web pages and files shown in this section.
1. Open a web browser, and navigate to the iOS Dev Center landing page at https://developer.apple.com/devcenter/ios.
2. Click the Log in button near the top of the page, and enter your Apple ID and password.
3. When a beta (developer preview) version is available, it appears as a link or button to the right of the main public version; click the button to access the beta area, shown in Figure 1.11.
4. Scroll down to the Downloads links. You can also click the Downloads link near the top left.
5. Click the Xcode and iOS download link to begin downloading Xcode. Depending on your browser and your individual preferences, you may choose to download the file to a specific location. Otherwise, the file will be copied to /Downloads on your Mac.
6. Wait… until the download completes.
7. Create a new folder on the root of your system disk. The name doesn’t matter, but “iOS Beta” is a good choice.
8. Navigate to the downloaded .dmg file in Finder.
While you can install this version manually into /Applications, it’s better to keep it in a different custom folder. You also may want to rename to avoid confusion with the current public version, especially if you also move it to the Dock.
1.11 The iOS beta/preview area is available only to members of the Developer Program.
9. Double-click the .dmg file. The contents should appear in a new window. You’ll see the .dmg file appear under the Devices list at the left of Finder.
10. Drag the Xcode file from the new window to the folder you created in Step 7, as shown in Figure 1.12.
11. Double-click the Xcode file to launch it. You can also drag its icon to the Dock for convenience.
If you enroll as a developer, you’ll often have two versions of Xcode in the Dock at the same time—the public version, used for current app development, and a beta/preview. You can rename the application files by hand to tell them apart. For example, you can rename the preview version to Xcode Beta.
In addition to the /Developer and /Beta folders, you should also create one or more project folders for your apps. Do not save apps inside the Xcode folders; they can be deleted without notice when you install an update.
1.12 Currently, you can install the developer version of Xcode by dragging it to a folder of your choice.
Understanding other installation requirements
There’s more to know about the preview process—and more files to download. In addition to the most recent version of Xcode with the newest SDK, you must also download the following:
A firmware update file for each of your test devices. This file updates the device to run the latest preview/beta version of iOS.
Xcode’s internal documentation files. This process is described later in this chapter.
Optionally, a new version of iTunes. Apple is moving to on-air updates of iOS devices, which means that iTunes is no longer required for iOS updates. However, this option isn’t always available, so you may still need to download a special beta/preview version of iTunes before you can update the firmware in your devices.
Developer versions of iTunes download and install like any other .dmg packaged application: Double-click the .dmg file to mount it, and then double-click the installer. One critical difference is that preview versions of iTunes usually include a built-in expiration date. After a preview expires, you can download the most recent version of iTunes from www.apple.com/itunes.
It should be obvious from this list that updating your development tools to the most recent SDK can mean lots of downloading. The total bandwidth for a new beta/preview SDK with Xcode, firmware for a single device, and associated documentation can total more than 5GB. If you have multiple test devices and need to update to a preview of iTunes, this can climb toward 7GB.
Updates can happen weekly. It’s not obligatory to download every preview/beta; you can usually skip some of the earlier betas, but expect to download at least 15-20GB a month.
Some broadband ISP contracts limit the amount of data you can download each month. If your broadband supplier implements a bandwidth cap, consider switching to a supplier that doesn’t limit you in this way.
Updating devices
Firmware is supplied either as a .dmg file or as an .ipsw file. (To find the .ipsw file inside a .dmg file, double-click it to open it.)
To update a device to the latest preview version of iOS with iTunes, follow these steps:
1. Connect your device to your Mac using a cable, and launch iTunes. (Although iTunes offers backup over WiFi and to iCloud, cable connections are more reliable.)
2. Select the device from the list at the left.
3. Click the option labeled Back up to this computer in the Backup pane. Optionally, you can also set a password.
4. Click the Sync button at the bottom right. Wait for the backup to complete.
5. Hold down the option button on your Mac’s keyboard, and click Restore.
6. Navigate to the .ipsw file you downloaded, select it, and click Open, as shown in Figure 1.13. If the .ipsw file was packed inside a .dmg file, select the .dmg file from the list of Devices at the left, and then select the .ipsw file.
1.13 Selecting a preview/beta version of iOS in iTunes to install it.
7. Wait while iTunes flashes the new version of iOS to your device. This can take 10-15 minutes.
8. The Set Up Your (iOS Device) page appears automatically in iTunes. Select your most recent backup from the menu on this page, and click Continue.
9. Wait while iTunes restores your apps, data, and settings. This can take another 15-20 minutes.
10. Your device can now be used for testing with the latest developer version of Xcode.
If you have multiple devices—for example, more than one iPhone, an iPhone and an iPad, an iPhone and an iPod Touch—you must update all devices you want to use for testing with the new version of iOS.
Installing documentation
Although Xcode is a huge download, it doesn’t include all the documentation and help files you need. To install these files, follow these steps:
1. Launch Xcode.
2. Select Xcode→Preferences from the main menu.
3. Click the Downloads icon near the top of the pane.
4. Click the Documentation tab.
5. Click the Check and Install Now button, as shown in Figure 1.14.
1.14 Reviewing the installed documentation. You don’t need every possible file, just the more recent ones.
Each file is 300-400MB. You don’t need to install every file; for example, you don’t need the OS X 10.6 Core Library if you’re developing iOS apps. But you do need the files for the current version of iOS and the Xcode Developer Library for help with Xcode itself.
If you check the check box labeled Check for and install updates automatically at the top left of this page, Xcode downloads all the documentation it needs as soon as it can. However, the download process isn’t bullet-proof, so you should always check manually that files have downloaded correctly.
Now that you’ve learned about the Developer Program, SDKs, and Xcode, you’re ready to start exploring Xcode’s developer-friendly features in more detail.
Chapter 2: How Do I Get Started with Xcode?
Xcode is a powerful package with many features. You don’t need to master it all to get started, but you do need to have a basic understanding of its most obvious features. In addition to getting started with Xcode, you also need to start learning about iOS and the technical details of app design. You can find help for all these topics in Apple’s official documentation and in supporting unofficial documentation that can be yours for the price of a web search.
Understanding Xcode
Introducing Xcode’s User Interface
Introducing iOS and the Apple Documentation
Getting Further Help
Putting It All Together
Understanding Xcode
Xcode is a tool for converting code—text instructions—into an app that can run on an iOS device.
Apps are built from more than one kind of data. In addition to the raw binary instructions that run on the processor, apps also include sound files, graphic files that define screens, backgrounds, buttons or game tokens, font files, and other supporting information.
When you build an app, Xcode combines these elements into a single file, called the product. Most of the build process is automatic.
You have three jobs as a developer:
Creating code. Code is kept in a collection of text files. The instructions you create define how the app responds to events and circumstances, such as a finger tap, a finger drag, an incoming message or notification, an out-of-memory error, and so on. Xcode includes a code editor to help you write code.
Creating a look and feel. Xcode includes a design tool called Interface Builder, shown in Figure 2.1,that manages the look and feel of the app. You can use it to place buttons and switches, control the order in which screens appear to the user, and define the graphics the user sees.
Managing files. You’ll often have to create files using an outside editor; for example, you may want to create a background screen in Adobe Photoshop. Xcode includes a file manager called the Navigator that tells Xcode which supporting files you want to include in your app.
Writing good code can be difficult, so Xcode includes many further features to help you:
A debugger. This tool helps you eliminate mistakes (“bugs”). You can literally step through your code line by line to confirm that each line is working as you think it should.
A complete documentation library. Every feature in iOS is documented in detail. There are also pre-written code examples, introductory orientation essays with live links to further help, introductory tutorials, and video descriptions of key elements.
A small library of app templates, code snippets, and standard graphics. In fact, there’s more than one library. You can use this feature to include buttons, sliders, and other standard iOS features in your app and to add boilerplate code to manage them.
2.1 A first look at Interface Builder, Xcode’s graphical app design tool. The Navigator area is at the left of the screen.
Live testing. These include the Simulator mentioned in Chapter 1. A further set of tools, called Instruments, is shown in Figure 2.2. Instruments can check the memory usage and performance of an app, in detail, while it’s running. Xcode can also be set up to work with a collection of specific iOS devices, and you can collect crash and memory information from these devices, even after testing is complete.
You can see that Xcode has many features. But it doesn’t have many windows. The interface has been condensed, so you’ll spend most of your time working in one main window that can be set to display up to four panes.
An optional further floating window is used to display supporting information, including Xcode’s documentation. You also can occasionally open a preferences window to set up various Xcode options.
2.2 Introducing Instruments, Xcode’s performance and resource testing tool.
Xcode is not a consumer product. It’s important to understand that as a developer, you’re expected to solve problems using your own initiative. Critical features in Xcode—which can include installation and delivery options—change regularly. Often you have no more than a few terse notes and perhaps some online discussion to help you. For better or worse, this self-sufficiency is part of developer culture. If you’re used to working with more streamlined and stable consumer products, it can leave you with some culture shock.
Introducing Xcode’s User Interface
When you launch Xcode for the first time, you see the Welcome to Xcode window shown in Figure 2.3. With the four options here, you can do the following:
Create a new Xcode project. Clicking this button takes you to Xcode’s project templates, which are described in Chapter 3.
Connect to a repository. You can use this feature to access a web repository to download, upload, or share code, as discussed in Chapter 13. If you’re new to Xcode, you can ignore this option for now.
Learn about using Xcode. This option opens a new window with a documentation viewer. If this is your first view of Xcode, it can be worth reviewing this introductory information, although most of it is covered more comprehensively—and perhaps accessibly—in this book.
Go to Apple’s developer portal. This opens your web browser and loads the main developer page at http://developer.apple/com. You can’t change this link, and the iOS Dev Center pages at http://developer.apple.com/devcenter/ios are more useful. So you won’t be using this option much.
2.3 Welcome to Xcode. Experienced developers often bypass this window.
Although it’s down to personal taste, many developers deselect the Show this window when Xcode launches check box near the bottom left of the pane. Although the Recents list of projects at the right can be useful, both the recent files and the other features in this window here can be accessed just as quickly from the main menu in Xcode.
Introducing the main Xcode window
Xcode’s main window, shown in Figure 2.4, has six main elements. You can use the buttons at the top right of the toolbar at the top of the screen to control which elements are visible.
A user interface (UI) defines the windows, panes, menus, and other features a user can access to work with an application. As a developer, you’ll spend lots of time defining the UI of your apps. A good UI is easy to understand, with a clear relationship between obvious features and useful tasks. The relationship between a UI and the features of an app is called the User Experience, often abbreviated to UX.
2.4 You’ll spend most of your development time in the main Xcode window.
The elements are described in detail later in this chapter. But let’s start with a quick overview.
The main toolbar. This includes the buttons that control Xcode’s critical features.
A tabbed file area. This small area under the toolbar works like the tab feature in most web browsers. You can have multiple files open at the same time, and you can switch between them by clicking them.
The Navigator. This area at the left of the window is a combined file selector and status/information area. You can select what it does by clicking the icons above it. Typically you use the Navigator to select files as you edit. Occasionally, you’ll use one of its other features, introduced later in this chapter.
The Editor. This area in the middle of the window displays code and other information you can change. Although it looks like a simple text editor, it has powerful code-editing features.
The Utility Area. The area at the right of the window displays supporting information, including quick help reminders, pre-written code snippets, and details about selected files that don’t fit elsewhere. Like the Navigator, you can select different features by clicking the icons that appear above it.
The Debugger. This area slides up from the bottom of the screen into the Editor area. It displays information and status messages that tell you what your app is doing while you debug it.
One further feature, called the Organizer, is shown in Figure 2.5. The Organizer is a grab-bag of features and options that don’t fit anywhere else. Like the other features, it’s described in detail later in this chapter. A critical point to remember is that the Organizer includes access to the iOS documentation.
You can drag the vertical dividing lines between the areas to resize them.
Viewing and hiding UI features