1. Getting Xcode

If you want to use Xcode, you must install it. Developer tools were bundled into OS X in the early days, but now you must download it, drag the Xcode application into your /Applications folder, and start it up.

Before You Begin

Before you do anything, be sure you can use Xcode 6. There are two considerations.

Developing for Earlier Operating Systems

When Apple brings out a new version of Xcode, it includes software development kits (SDKs) for the latest version of iOS (8) and the versions of OS X that it can run on (Mavericks 10.9 and Yosemite 10.10). In theory, that isn’t much of a constraint: You can still target earlier OSes; the SDK does the right thing to adapt itself to the earlier versions.

However, there are some APIs that don’t make the cut. (An earlier, incompatible version of libcrypto was dropped in OS X 10.6 after warnings more than a year in advance.) The same with PowerPC development: If you need to do that, get a Mac that can run 10.6 and use Xcode 3.2.6. I’ll explain how use the xcode-select tool to switch your system between versions of Xcode in the “Command-Line Tools” section of Chapter 25, “The Xcode Build System.”


Note

People have asked whether they can pluck SDKs from earlier Xcode installations and drop them into Xcode 6. Ultimately it doesn’t work: The older SDKs rely on compilers and runtime libraries that are not available in Xcode 6, and Xcode 6 assumes that its SDKs are built to support the tools it does have. To quote an Apple Developer Tools engineer, “Xcode receives zero testing in these unsupported configurations.”


Requirements

Apple is cagey about what the operating requirements are for Xcode, and that’s understandable, because it depends on your usage and preferences.

Image Xcode 6 runs on OS X Mavericks (10.9) and Yosemite (10.10).

Image The download will be about 2 GB.

Image How much disk space the installed Xcode takes up depends on what documentation sets and supplementary tools you download. A fresh installation is about 6.5 GB; 9 GB is not uncommon with options.

Image Xcode 6 can be run in 2 GB of memory, but don’t expect to do much more than look at it. For the examples in this book, 4 GB should be enough, but for medium-sized projects, my rule of thumb is that you’ll need about 3 GB, plus another 750 MB for each processor core in your machine. Get more RAM if you can; I don’t know anybody who has reached the point of diminishing returns.

Image Xcode is a 64-bit Intel application. The minima for this book are 64-bit, dual-core, and 1.2 GHz. More is better.

Image Bigger—particularly, wider—displays are better. I’m writing on a MacBook Air with 1,440 points’ horizontal resolution. With the display-management techniques I’ll show you, it’s comfortable most of the time. And with my 15" Retina MacBook Pro set to show the maximum content, I have no complaints.

The bottom-of-the-line Mac mini on sale as I write this ($599 in the U.S., plus display, keyboard, and mouse) is fine for the purposes of Xcode 6 Start to Finish, as are most Macs sold since 2010.


Note

Xcode 6 Start to Finish was written using Xcode up through version 6.2 on a Mac running OS X 10.10 Yosemite, with allowances for Swift 1.2. If you’re using Mavericks, be aware that the appearance of the windows won’t match what you see in the illustrations, and some exercises—Mac storyboards in particular—will not be possible without Yosemite.


Installing Xcode

For most purposes, obtaining Xcode 6 is very easy: Find it in the Mac App Store (MAS), enter your Apple ID and password, and download it. It’s free. See “Downloading Xcode,” later in this chapter, for another option, and why you might need it.

Once the download is complete, Xcode will be in your /Applications folder.


Note

Want to see everything you got? Right-click the Xcode icon in /Applications, and select Show Package Contents. You’ll see the directories and files behind the pseudo-file representing Xcode. Poke around all you like, but don’t make any changes.


There’s no step three. There are no installation options—there’s no installer. In earlier versions, developer tools were put in a /Developer directory at the root of the boot volume (or the one you selected in the installer). No more: All the tools you need for basic iOS and Mac development are contained in Xcode itself.

Most of the documentation isn’t installed. Xcode will download it the first time you run it. It’s not practical to bundle it into the Xcode download: It runs hundreds of megabytes, it changes more frequently than the developer tools, and you may not want it all. The Downloads panel of the Preferences window controls the downloads.

One advantage of MAS distribution is that once the App Store application knows it has installed Xcode, it can alert you to updates. When you accept an update, the App Store sends only the components that changed, greatly reducing the download time. Downloads smaller than 100 MB are not unknown.

Command-Line Tools

As installed, Mavericks and Yosemite contain executable files in /usr/bin that have the names of common development tools—make, gcc, clang, and so on. Open-source projects that must be built before being installed expect to find those tools in that directory. But they aren’t the actual programs that go by those names. They are trampolines; when you run them, they hand off to the real programs elsewhere in the system:

Image To the tools embedded in the Xcode application package, if Xcode is present.

Image To the tools in /Library/Developer, if present. This is where the contents of the optional command-line tools package go.

Image If none can be found, the trampoline program will offer to download and install the command-line tools package. You can also do this by executing sudo xcode-select --install.

In any case, the executable files in /usr/bin will always be trampolines.

So if you’re running Xcode 6, you don’t need a separate package of developer tools. The system will act as though they were there already—and your Xcode and command-line builds will use the same tools, which should make most developers a lot less nervous.

If you don’t want Xcode 6, don’t install it. Run one of the tools, or go to http://developer.apple.com/downloads and grab an installer; be sure to get the version that goes with your version of OS X.

Removing Xcode

Your life has changed. The honeymoon is over. You’ve had your look, and you’re done. You’ve decided to edit a theatrical feature and you need the space. You’re giving your Mac to your daughter in art school. For whatever reason, you’re done with Xcode. How do you get rid of it?

In the early days of Xcode, this involved uninstall scripts and directory deletions. Now, you just drag the Xcode application into the Trash, and you’re done. Almost.

The reason uninstallation was so complicated in earlier Xcodes was that you had to get rid of the tools, libraries, headers, and frameworks that Xcode would infiltrate throughout the system. The scripts ran down the inventory and rooted out each item.

But remember what I said earlier about the command-line tools: The tools and other files are all inside Xcode. Everything else out in the system is a trampoline to those files. Throw away Xcode, and you’ll have gotten rid of what previously had been infiltrations. . .

. . . unless you installed the stand-alone Command Line Developer Tools package. You can find those in /Library/Developer/ along with some large documentation libraries. Delete that directory. Do the same with ~/Library/Developer/.

Apple Developer Programs

Anyone can pick up Xcode 6 for free and start developing OS X and iOS software. If your interest is in distributing Mac software on your own, your preparation is done: Build your apps, put them on the Net, and God bless you.

However, if you want to distribute your work on the Mac or iOS App Store; assure users with Gatekeeper that your Mac apps are safe; or even test your iOS app on a device, you have to go further. You’ll need to pay for a membership in the Mac or iOS Developer Program. (If you need to, you can join both.)

Apple’s policies and methods for joining developer programs are subject to change, so the best I can do for you is to give an overview. Start by browsing to http://developer.apple.com/. Prominently featured will be links to join the iOS and Mac developer programs. The programs will give you:

Image Access to prerelease software, including operating systems and developer tools.

Image Access to the parts of the developer forums (http://devforums.apple.com/) that cover nondisclosed topics.

Image Two incidents with Developer Technical Support (DTS), Apple engineers who can advise you on development strategies and help you with troubleshooting. This is the only official, guaranteed way to get help from Apple. If you have the time, by all means go to a developer forum or mailing list first (you’ll find lots of leads in Appendix B, “Resources”), but if that fails, DTS is the best choice.

Image The right to submit your applications for sale in the Mac or iOS App Store.

Image In the case of iOS, the right to load your app into a device for debugging purposes (see Chapter 18, “Provisioning,” for details).

Image In the case of OS X, a Developer ID certificate that enables users who use Gatekeeper to install your app.

Make your choice (whichever you choose, you’ll be offered both programs), and you will be taken to a page with an Enroll Now button, citing the cost of a year’s membership ($99 in the United States as I write this).

The next step is to establish your status as a “registered Apple developer.” Registered developers have few privileges beyond having a persistent record with Apple that can be used to sign up for developer programs. (There are a limited number of resources to which your assent to terms and conditions entitles you, such as access to the released-product sections of the developer forums.) If you’re already registered, say so, and skip to the signup process. If you’re not, present your Apple ID (such as you might be using with iTunes) or get one, fill out marketing and demographic questionnaires, and assent to the terms and conditions of Apple programs. They’ll send you an email you can use to verify your contact information.

Once that’s done, you’re given your choice of programs. Select all you are interested in and can afford; the iOS and Mac programs incur separate charges, and there’s no discount. There’s also a free Safari program, which allows you to develop and sign extensions for the desktop Safari web browser.

Next you’ll have program-specific licenses to agree to. When that’s done, you’re a member.

Downloading Xcode

The App Store download is convenient, but it’s not for everybody. New versions of Xcode—even point releases—may drop features on which you may have relied. Xcode supports keeping more than one copy of the application on your computer, but the App Store doesn’t. When you accept an update from the App Store, it seeks out older versions, wherever they may be, and deletes them. You’ll have to take control of the process yourself.


Note

See Chapter 25, “The Xcode Build System,” for the xcode-select and xcrun command-line tools that support using multiple versions of Xcode.


If you’re a developer program member (even a member of the free program), you have access to http://developer.apple.com/downloads. Use the checkboxes to narrow the listing to developer tools. You will find every Xcode toolset going back to 1.0 (a 584-MB CD image for OS X 10.3). The currently released version of Xcode will be near the top. Download it.

If you want a version that Apple has not put out as a public beta, you’ll have to go to either the iOS or OS X developer center, log in with your paid developer-program credentials, select the prerelease section, and receive a Mac App Store redemption code. This will get you the first prerelease version of Xcode, which the Mac App Store application will update.

You’ll end up with a compressed disk-image (.dmg) file. Double-click it to reveal the Xcode application. Drag it into /Applications, or wherever you like. If you want to preserve an earlier version, rename that copy first.

Updates carry two penalties compared to the MAS method: You’ll have to keep track of their availability yourself, and you’ll have to download the whole toolset again. No incremental updates for you.


Warning

Apple’s official position is that Xcode 6 is the only version it will support on Yosemite. Historically, Apple has been very conservative with the word “support” as it applies to previous versions of developer tools on newer operating systems. My interpretation is that Developer Tools has enough on its hands building a major version of Xcode without exhaustively testing and revising the version they were making obsolete. Maybe it works, maybe it doesn’t, but Apple isn’t going to stand behind it.


Additional Downloads

Download files for early versions of Xcode topped out at 3 GB. The Xcode 4.3 image was just over half that size, 1.8 GB.

One way Apple keeps download sizes down is to provide only stubs for OS X and iOS documentation. The first time you run Xcode, it triggers a download of the full documentation sets. This annoys people who want 100 percent functionality after installing Xcode aboard airplanes, but there’s really no alternative: Not everybody needs every documentation set. Further, Apple updates its documentation much more often than it updates Xcode, so even if the download included full documentation, you’d have to pull in the current docs anyway.

Another trick for reducing download size is to recognize that not everybody needs every development tool. Apple has broken seven toolsets out into downloadable archives. Not only does this keep these files out of the main download, it allows Apple to free them from the release cycle of Xcode itself.

Here are the available packages as I write this:

Image Accessibility—Tools for auditing and testing accessibility support of your Mac applications.

Image Audio—Applications for examining Core Audio units, plus headers and sample code.

Image Auxiliary—Help Indexer (create Mac application help books), Repeat After Me (refine your text-to-speech translations), and tools for creating new dictionaries for the Mac Dictionary application.

Image Command-line tools—Commands you can use from the Terminal application for classic-style development; this is how you’d get the tools without needing Xcode even to install them.

Image Dashcode—Apple’s visual editor for HTML5/CSS/JavaScript to be used as OS X Dashboard widgets, and for iOS-like web applications.

Image Hardware IO—Probes for USB and Bluetooth, as well as the Network Link Conditioner, which allows you to degrade network performance and reliability to simulate mobile connectivity in the iOS Simulator.

Image Graphics—OpenGL development tools, and the Quartz Composer builder for chains of image and video filters.

If you want one of the supplemental toolsets, open Xcode and select XcodeOpen Developer ToolMore Developer Tools. . .. Your default browser will be directed to the developer downloads site, with the search string set to for Xcode -, which will show you what’s available.

When you find what you need, click the disclosure triangle to show a description of the package and a link to download it. You’ll be asked to read and accept the general license for Apple’s developer tools. Agree, and the download will start.

What you’ll get is a .dmg disk image containing applications and installers. Drag the apps into /Applications, or wherever else you find convenient—they will not appear under the Xcode menu.

In addition to the specialized toolsets, there are other components like device-debugging software and simulators for back versions of iOS. Use the Preferences window, Downloads panel, Components section to download and install them if you need them.

Summary

Apple has tried to strike a balance between making Xcode easily available to everybody, and providing choices about what and how much to install. The free installation from the Mac App Store will get you everything you need to get started with iOS and OS X development. If your needs are more specialized—if you need older versions, or customized toolsets—the developer downloads site has it all.

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

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