Beginning iPhone Development With Swift 2 Exploring the iOS SDK 2nd Edition David Mark instant download
Beginning iPhone Development With Swift 2 Exploring the iOS SDK 2nd Edition David Mark instant download
https://ebookgate.com/product/beginning-iphone-development-with-
swift-2-exploring-the-ios-sdk-2nd-edition-david-mark/
https://ebookgate.com/product/beginning-iphone-development-exploring-
the-iphone-sdk-1st-edition-jeff-lamarche/
ebookgate.com
https://ebookgate.com/product/ios-9-sdk-development-creating-iphone-
and-ipad-apps-with-swift-1st-edition-adamson/
ebookgate.com
https://ebookgate.com/product/the-iphone-developer-s-cookbook-
building-applications-with-the-iphone-3-0-sdk-2nd-edition-erica-sadun/
ebookgate.com
https://ebookgate.com/product/ios-swift-game-development-cookbook-2nd-
edition-simple-solutions-for-game-development-problems-jonathon-
manning/
ebookgate.com
iOS 12 App Development Essentials Learn to Develop iOS 12
Apps with Xcode 10 and Swift 4 Neil Smyth
https://ebookgate.com/product/ios-12-app-development-essentials-learn-
to-develop-ios-12-apps-with-xcode-10-and-swift-4-neil-smyth/
ebookgate.com
https://ebookgate.com/product/beginning-ios-storyboarding-with-xcode-
lewis/
ebookgate.com
https://ebookgate.com/product/beginning-java-2-sdk-1-4-edition-ivor-
horton/
ebookgate.com
https://ebookgate.com/product/head-first-iphone-development-covers-
iphone-3-1-sdk-a-brain-friendly-guide-1st-ed-edition-pilone/
ebookgate.com
https://ebookgate.com/product/iphone-sdk-3-programming-advanced-
mobile-development-for-apple-iphone-and-ipod-touch-1st-edition-maher-
ali/
ebookgate.com
Beginning
iPhone Development
with Swift 2
Exploring the iOS SDK
—
Learn to build iPhone and iPad apps
using the iOS SDK and Swift 2
—
David Mark
Kim Topley
Jack Nutting
Fredrik Olsson
Jeff LaMarche
www.allitebooks.com
Beginning iPhone
Development with
Swift 2
Exploring the iOS SDK
David Mark
Kim Topley
Jack Nutting
Frederik Olsson
Jeff LaMarche
www.allitebooks.com
Beginning iPhone Development with Swift: Exploring the iOS SDK
Copyright © 2015 by David Mark, Kim Topley, Jack Nutting, Frederik Olsson, and Jeff LaMarche
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with
reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed
on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or
parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its
current version, and permission for use must always be obtained from Springer. Permissions for use may be
obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under
the respective Copyright Law.
ISBN-13 (pbk): 978-1-4842-1753-5
ISBN-13 (electronic): 978-1-4842-1754-2
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol
with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only
in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director: Welmoed Spahr
Lead Editor: Steve Anglin
Development Editor: Matthew Moodie
Technical Reviewer: Bruce Wade
Editorial Board: Steve Anglin, Pramila Balan, Louise Corrigan, Jonathan Gennick, Robert Hutchinson,
Celestin Suresh John, Michelle Lowman, James Markham, Susan McDermott, Matthew Moodie,
Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Gwenan Spearing
Coordinating Editor: Mark Powers
Copy Editor: Kimberly Burton
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,
6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com,
or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer
Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail rights@apress.com, or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use.
eBook versions and licenses are also available for most titles. For more information, reference our Special
Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this text is available to
readers at www.apress.com/9781484217535. For detailed information about how to locate your book’s source
code, go to www.apress.com/source-code/. Readers can also access source code at SpringerLink in the
Supplementary Material section for each chapter.
www.allitebooks.com
This book is dedicated to the memory of Steve Jobs. We continue to be inspired by
his spirit and his vision.
—David Mark and Jack Nutting
For Diana.
—Kim Topley
www.allitebooks.com
Contents at a Glance
About the Authors���������������������������������������������������������������������������������������������������xxi
About the Technical Reviewer������������������������������������������������������������������������������xxiii
■
■Chapter 1: Welcome to the Swift Jungle��������������������������������������������������������������� 1
■
■Chapter 2: Appeasing the Tiki Gods��������������������������������������������������������������������� 13
■
■Chapter 3: Handling Basic Interaction����������������������������������������������������������������� 55
■
■Chapter 4: More User Interface Fun�������������������������������������������������������������������� 91
■
■Chapter 5: Rotation and Adaptive Layout���������������������������������������������������������� 141
■
■Chapter 6: Multiview Applications�������������������������������������������������������������������� 181
■
■Chapter 7: Tab Bars and Pickers ���������������������������������������������������������������������� 211
■
■Chapter 8: Introduction to Table Views������������������������������������������������������������� 255
■
■Chapter 9: Navigation Controllers and Table Views������������������������������������������� 307
■
■Chapter 10: Collection View and Stack View����������������������������������������������������� 341
■
■Chapter 11: Using Split Views and Popovers����������������������������������������������������� 371
■
■Chapter 12: Application Settings and User Defaults������������������������������������������ 411
■
■Chapter 13: Basic Data Persistence������������������������������������������������������������������ 453
■
■Chapter 14: Documents and iCloud������������������������������������������������������������������� 503
www.allitebooks.com
vi Contents at a Glance
■
■Chapter 15: Grand Central Dispatch, Background Processing, and You������������ 539
■
■Chapter 16: Drawing with Core Graphics���������������������������������������������������������� 575
■
■Chapter 17: Getting Started with SpriteKit�������������������������������������������������������� 603
■
■Chapter 18: Taps, Touches, and Gestures���������������������������������������������������������� 655
■
■Chapter 19: Where Am I? Finding Your Way with Core Location and Map Kit���� 689
■
■Chapter 20: Whee! Gyro and Accelerometer!���������������������������������������������������� 711
■
■Chapter 21: The Camera and Photo Library������������������������������������������������������� 737
■
■Chapter 22: Application Localization����������������������������������������������������������������� 749
■
■Appendix A: A Swift Introduction to Swift��������������������������������������������������������� 777
Index��������������������������������������������������������������������������������������������������������������������� 839
www.allitebooks.com
Contents
About the Authors���������������������������������������������������������������������������������������������������xxi
About the Technical Reviewer������������������������������������������������������������������������������xxiii
■
■Chapter 1: Welcome to the Swift Jungle��������������������������������������������������������������� 1
What This Book Is������������������������������������������������������������������������������������������������������������� 1
What You Need����������������������������������������������������������������������������������������������������������������� 2
Developer Options���������������������������������������������������������������������������������������������������������������������������������� 3
What You Need to Know������������������������������������������������������������������������������������������������������������������������� 4
vii
www.allitebooks.com
viii Contents
www.allitebooks.com
Contents ix
■
■Chapter 4: More User Interface Fun�������������������������������������������������������������������� 91
A Screen Full of Controls������������������������������������������������������������������������������������������������ 91
Active, Static, and Passive Controls�������������������������������������������������������������������������������� 95
Creating the Application������������������������������������������������������������������������������������������������� 97
Implementing the Image View and Text Fields��������������������������������������������������������������� 97
Adding the Image View������������������������������������������������������������������������������������������������������������������������� 98
Resizing the Image View�������������������������������������������������������������������������������������������������������������������� 100
Setting View Attributes����������������������������������������������������������������������������������������������������������������������� 102
Adding the Text Fields������������������������������������������������������������������������������������������������������������������������� 105
Adding Constraints����������������������������������������������������������������������������������������������������������������������������� 113
Creating and Connecting Outlets�������������������������������������������������������������������������������������������������������� 115
www.allitebooks.com
x Contents
■
■Chapter 5: Rotation and Adaptive Layout���������������������������������������������������������� 141
The Mechanics of Rotation������������������������������������������������������������������������������������������� 142
Points, Pixels, and the Retina Display������������������������������������������������������������������������������������������������� 143
Handling Rotation������������������������������������������������������������������������������������������������������������������������������� 143
www.allitebooks.com
Contents xi
■
■Chapter 7: Tab Bars and Pickers ���������������������������������������������������������������������� 211
The Pickers Application������������������������������������������������������������������������������������������������ 212
Delegates and Data Sources���������������������������������������������������������������������������������������� 217
Creating the Pickers Application���������������������������������������������������������������������������������� 218
Creating the View Controllers������������������������������������������������������������������������������������������������������������� 218
Creating the Tab Bar Controller����������������������������������������������������������������������������������������������������������� 219
The Initial Test Run����������������������������������������������������������������������������������������������������������������������������� 223
■
■Chapter 11: Using Split Views and Popovers����������������������������������������������������� 371
Building Master-Detail Applications with UISplitViewController����������������������������������� 375
The Storyboard Defines the Structure������������������������������������������������������������������������������������������������ 377
The Code Defines the Functionality���������������������������������������������������������������������������������������������������� 379
How the Master-Detail Template Application Works��������������������������������������������������������������������������� 383
Index��������������������������������������������������������������������������������������������������������������������� 839
www.allitebooks.com
About the Authors
Dave Mark is a longtime Mac developer and author who has
written a number of books on Mac and iOS development,
including Beginning iOS 6 Development (Apress, 2013),
More iOS 6 Development (Apress, 2013), Learn C on the Mac
(Apress, 2013), Ultimate Mac Programming (Wiley, 1995), and
the Macintosh Programming Primer series (Addison-Wesley,
1992). Dave was one of the founders of MartianCraft, an iOS
and Android development house. Dave loves the water and
spends as much time as possible on it, in it, or near it. He lives
with his wife and three children in Virginia. On Twitter, he’s
@davemark.
xxi
xxii About the Authors
Jack Nutting has been using Cocoa since the olden days, long
before it was even called Cocoa. He has used Cocoa and its
predecessors to develop software for a wide range of industries
and applications, including gaming, graphic design, online
digital distribution, telecommunications, finance, publishing,
and travel. Jack has written several books on iOS and Mac
development, including Beginning iOS 6 Development (Apress,
2013), Learn Cocoa on the Mac (Apress, 2013), and Beginning
iPad Development for iPhone Developers (Apress, 2010).
Besides writing software and books, he also leads developer
training and blogs from time to time at www.nuthole.com. He’s
@jacknutting on Twitter.
xxiii
Chapter 1
Welcome to the Swift Jungle
So, you want to write iPhone, iPod touch, and iPad applications? Well, we can’t say that we
blame you. iOS—the core software of all of these devices—is an exciting platform that has
been seeing explosive growth since it first came out in 2007. The rise of the mobile software
platform means that people are using software everywhere they go. With the release of iOS 9,
Xcode 7, and the latest incarnation of the iOS software development kit (SDK), things have
only gotten better and more interesting.
Tip Dave, Jack, Jeff, and Fredrik have set up a forum for this book. It’s a great place to meet
like-minded folks, get your questions answered, and even answer other people’s questions.
The forum is at http://forum.learncocoa.org. Be sure to check it out!
1
2 CHAPTER 1: Welcome to the Swift Jungle
Click on iOS to go to the main resources page for the current production release and (if there
is one) the current beta release of iOS. Here, you’ll find links to a wealth of documentation,
videos, sample code, and the like—all dedicated to teaching you the finer points of iOS
application development. Be sure to scroll to the bottom of the page and check out the links
to the Documentation and Videos sections of the web site. You’ll also find a link to the Apple
Developer Forums, where you can follow discussions on a wide variety of topics covering
the whole iOS platform, as well as OS X and watchOS (the operating system for the Apple
Watch), although you’ll need to be a registered Apple developer to post to the forums.
The most important tool you’ll be using to develop iOS applications is called Xcode. Xcode
is Apple’s integrated development environment (IDE). Xcode includes tools for creating and
debugging source code, compiling applications, and performance-tuning the applications
you’ve written.
You can download the current beta release of Xcode by following the Xcode link from the
developer resources page in Figure 1-1. If you prefer to use the latest production release,
you’ll find it in the Mac App Store, which you can access from your Mac’s Apple menu.
As the versions of the SDK and Xcode evolve, the mechanism for downloading them has also been changing.
For the past few years, Apple has been publishing the current “stable” version of Xcode and the iOS SDK on the
Mac App Store, while simultaneously providing developers the ability to download preview versions of upcoming
releases from its developer site. Bottom line: unless you really want to work with the most recent development
tools and platform SDK, you usually want to download the latest released (non-beta) version of Xcode and the
iOS SDK, so use the Mac App Store.
This book has been written to work with the latest versions of Xcode and the SDK. In some places, we have
chosen to use new functions or methods introduced with iOS 9 that are not available in earlier versions of the
SDK. We’ll be sure to point those situations out as they arise in this book.
Be sure to download the latest and greatest source code archive for examples from this book’s page at
http://apress.com. We’ll update the code as new versions of the SDK are released, so be sure to check the
site periodically.
Developer Options
The free Xcode download includes a simulator that will allow you to build and run
iPhone and iPad apps on your Mac. This is perfect for learning how to program for iOS.
However, the simulator does not support many hardware-dependent features, such as the
accelerometer and camera. To test applications that use those features, you’ll need an
iPhone, iPod touch, or iPad. While much of your code can be tested using the iOS simulator,
not all programs can be. And even those that can run on the simulator really need to be
thoroughly tested on an actual device before you ever consider releasing your application to
the public.
4 CHAPTER 1: Welcome to the Swift Jungle
Previous versions of Xcode required you to register for the Apple developer program
(which is not free) to install your applications on a real iPhone or other device. Fortunately,
this has changed. Xcode 7 allows you to test applications on real hardware, albeit with
some limitations that we’ll cover as we go along, without purchasing an Apple developer
membership. That means you can run most of the examples in this book on your iPhone
or iPad for free! However, the free option does not give you the ability to distribute your
applications on Apple’s App Store. For those capabilities, you’ll need to sign up for one of
the other options, which aren’t free:
The Standard program costs $99/year. It provides a host of development
tools and resources, technical support, distribution of your applications
via Apple’s iOS and Mac App Stores. Your membership lets you develop
and distribute applications for iOS, watchOS and OS X.
The Enterprise program costs $299/year. It is designed for companies
developing proprietary, in-house iOS applications.
For more details on these programs, visit https://developer.apple.com/programs. If you
are an independent developer, you can definitely get away with just buying the standard
program membership and you don’t have to do that until you need to run an application that
uses a feature such as iCloud that requires a paid membership, you want to post a question
to the Apple Developer forums or you are ready to deploy your application to the App Store.
Because iOS supports an always-connected mobile device that uses other companies’
wireless infrastructures, Apple has needed to place far more restrictions on iOS developers
than it ever has on Mac developers (who are able—at the moment, anyway—to write and
distribute programs with absolutely no oversight or approval from Apple). Even though the
iPod touch and the Wi-Fi-only versions of the iPad don’t use anyone else’s infrastructure,
they’re still subject to these same restrictions.
Apple has not added restrictions to be mean, but rather as an attempt to minimize the
chances of malicious or poorly written programs being distributed that could degrade
performance on the shared network. Developing for iOS may appear to present a lot of hoops
to jump through, but Apple has expended quite an effort to make the process as painless as
possible. And also consider that $99 is still much less expensive than buying, for example,
any of the paid versions of Visual Studio, which is Microsoft’s software development IDE.
You also need to be familiar with iOS itself, as a user. Just as you would with any platform for
which you wanted to write an application, get to know the nuances and quirks of the iPhone,
iPad, or iPod touch. Take the time to get familiar with the iOS interface and with the way
Apple’s iPhone and/or iPad applications look and feel.
Limited Access
Programs on a desktop or laptop computer pretty much have access to everything the
user who launched them does. However, iOS seriously restricts what your application can
access.
You can read and write files only from the part of iOS’s file system that was created for your
application. This area is called your application’s sandbox. Your sandbox is where your
application will store documents, preferences, and every other kind of data it may need to
retain.
Your application is also constrained in some other ways. You will not be able to access low-
number network ports on iOS, for example, or do anything else that would typically require
root or administrative access on a desktop computer.
The hardware size is the actual physical size of the screen in pixels. However, when writing
software, the size that really matters is the one in the Software Size column. As you can see,
in most cases, the software size is only half that of the actual hardware. This situation came
about when Apple introduced the first Retina device, which had twice as many pixels in each
direction as its predecessor. If Apple had done nothing special, all existing applications would
have been drawn at half-scale on the new Retina screen, which would have made them
unusable. So Apple chose to internally scale everything that applications draw by a factor
of 2, so that they would fill the new screen without any code changes. This internal scaling
by a factor of 2 applies to all devices with a Retina display, apart from the iPhone 6/6s Plus,
which has a higher-density screen that requires a scaling factor of 3. For the most part,
though, you don’t need to worry too much about the fact that your application is being
scaled—all you need to do is work within the software screen size and iOS will do the rest.
The only exceptions to this rule are bitmap images. Since bitmap images are, by their nature,
fixed in size, for best results you can’t really use the same image on a Retina screen as you
would on a non-Retina screen. If you try to do that, you’ll see that iOS scales your image up
for a device that has a Retina screen, which has the effect of introducing blur. You can fix this
by including separate copies of each image for the 2x and 3x Retina screens, and iOS will
pick the version that matches the screen of the device on which your application is running.
Note If you look back at Table 1-1, you’ll see that it appears that the scale factor in the fourth
column is the same as the ratio of the hardware size to the software size. For example, on the
iPhone 6/6s, the hardware width is 750 and software width is 375, a ratio of 2:1. Look carefully,
though, and you’ll see that there’s something different about the iPhone 6/6s Plus. The ratio of
the hardware width to the software width is 1080/414, which is 2.608:1, and the same applies to
the height ratio. So in terms of the hardware, the iPhone 6/6s Plus does not have a truly 3x Retina
display. However, as far as the software is concerned, a 3x scale is used, which means that an
application written to use the software screen size of 414 × 736 is first logically mapped to a virtual
screen size of 1242 × 2208 and the result is then scaled down a little to match the actual hardware
size of 1080 × 1920. Fortunately, this doesn’t require you to do anything special because iOS takes
care of all the details.
www.allitebooks.com
8 CHAPTER 1: Welcome to the Swift Jungle
A Different Approach
Two things iOS devices don’t have are a physical keyboard and a mouse, which means
you have a fundamentally different way of interacting with the user than you do when
programming for a general-purpose computer. Fortunately, most of that interaction is
handled for you. For example, if you add a text field to your application, iOS knows to bring
up a keyboard when the user touches that field, without you needing to write any extra code.
CHAPTER 1: Welcome to the Swift Jungle 9
Note All iOS devices allow you to connect an external keyboard via Bluetooth, which gives you a
nice keyboard experience and saves some screen real estate. Connecting a mouse is not an option.
Nearly every iOS device has a camera and a library of pictures, both of
which are available to your application, if you ask nicely! In Chapter 21,
we’ll show you how to ask nicely.
iOS devices are currently available in more than 90 countries. In Chapter 22,
we’ll show you how to write your applications in such a way that all
parts can be easily translated into other languages. This helps expand
the potential audience for your applications.
Finally, there’s an Appendix that introduces the Swift 2 programming
language and covers all of the features that you’ll need to know to
understand the example code in this book.
Tip Swift 2 added a new feature that makes it easy to check whether features that you need are
available on the platform that your application is running on. You’ll find the details in the appendix.
12 CHAPTER 1: Welcome to the Swift Jungle
If you find that some of the example source code no longer compiles with the release of
Xcode that you are using, please visit the book’s page at Apress.com and download the
latest version. If after doing this you are still having problems, please bring it to our attention
by submitting an Erratum at Apress.com.
Note Even though you have the complete set of project files at your disposal in this book’s source
code archive, you’ll get more out of the book if you create each project by hand, rather than simply
running the version you downloaded. By doing that, you’ll gain familiarity and expertise working
with the various application development tools.
There’s no substitute for actually creating applications; software development is not a spectator
sport.
13
14 CHAPTER 2: Appeasing the Tiki Gods
The project we’re going to build in this chapter is contained in the 02 - Hello World folder of
the source code archive.
Before we can start, we need to launch Xcode, the tool that we’ll use to do most of what
we do in this book. After downloading it from the Mac App Store or the Apple Developer
site, you’ll find it installed in the /Applications folder, as with most Mac applications. You’ll
be using Xcode a lot, so you might want to consider dragging it to your dock so you’ll have
ready access to it.
If this is your first time using Xcode, don’t worry; we’ll walk you through every step involved
in creating a new project. If you’re already an old hand but haven’t worked with Xcode 7, you
may find that some things have changed (mostly for the better, we think).
When you first launch Xcode, you’ll be presented with a welcome window like the one
shown in Figure 2-1. From here, you can choose to create a new project, connect to a
version-control system to check out an existing project, or select from a list of recently
opened projects. The welcome window gives you a nice starting point, covering some of the
most common tasks you’re likely to want to do after launching Xcode. All of these actions
can be accessed through the menu as well, so close the window, and we’ll proceed. If you
would rather not see this window in the future, just uncheck the Show this window when
Xcode launches check box at the bottom of the window before closing it.
Create a new project by selecting New ➤ Project… from the File menu (or by pressing
N). A new project window will open, showing you the project template selection sheet
(see Figure 2-2). From this sheet, you’ll choose a project template to use as a starting point
CHAPTER 2: Appeasing the Tiki Gods 15
for building your application. The pane on the left side of the sheet is divided into two main
sections: iOS and OS X. Since we’re building an iOS application, select Application in the
iOS section to reveal the iOS application templates.
Figure 2-2. The project template selection sheet lets you select from various templates when creating a new project
Each of the icons shown in the upper-right pane in Figure 2-2 represents a separate project
template that can be used as a starting point for your iOS applications. The icon labeled
Single View Application is the simplest template and the one we’ll be using for the first
several chapters. The other templates provide additional code and/or resources needed to
create common iPhone and iPad application interfaces, as you’ll see in later chapters.
Click the Single View Application icon (see Figure 2-2), and then click the Next button. You’ll
see the project options sheet, which should look like Figure 2-3. On this sheet, you need to
specify the Product Name and Company Identifier for your project. Xcode will combine these
to generate a unique bundle identifier for your app. You’ll also see a field that lets you enter an
Organization Name, which Xcode will use to automatically insert a copyright notice into every
source code file you create. Name your product Hello World and enter an organization name and
identifier in the Organization Name and Organization Identifier fields, as shown in Figure 2-3.
Don’t use the same name and identifier as the ones shown in Figure 2-3—for reasons that
you’ll see when we try to run this application on a real device at the end of the chapter, you’ll
need to choose an identifier that’s unique to you (or your company).
16 CHAPTER 2: Appeasing the Tiki Gods
Figure 2-3. Selecting a product name and organization identifier for your project
The Language field lets you select the programming language that you want to use. You
can choose between Objective-C and Swift, but since all of the examples in the book are in
Swift, the appropriate choice here is, of course, Swift.
We also need to specify the Devices. In other words, Xcode wants to know if we’re building
an app for the iPhone and iPod touch, if we’re building an app for the iPad, or if we’re
building a universal application that will run on all iOS devices. Select iPhone for the
Devices if it’s not already selected. This tells Xcode that we’ll be targeting this particular app
at the iPhone and iPod touch, which have roughly the same screen size and form factor. For
the first few chapters of the book, we’ll be using the iPhone device, but don’t worry—we’ll
cover the iPad also.
Leave the Core Data check box unchecked—we’ll make use of it in Chapter 13. We’ll also
leave the Include Unit Tests and Include UI Tests check boxes unchecked. Xcode has very
good support for testing of your applications, but that’s outside the scope of this book, so
we don’t need Xcode to include support for them in our project. Click Next again, and you’ll
be asked where to save your new project using a standard save sheet (see Figure 2-4). If you
haven’t already done so, jump over to the Finder, create a new master directory for these
book projects, and then return to Xcode and navigate into that directory. Before you click the
Create button, take note of the Source Control check box. We won’t be talking about Git in
this book, but Xcode includes some support for using Git and other kinds of source control
CHAPTER 2: Appeasing the Tiki Gods 17
management (SCM) tools. If you are already familiar with Git and want to use it, enable this
check box; otherwise, feel free to turn it off.
Note Source Control Management (SCM) is a technique for keeping track of changes made to an
application’s source code and resources while it’s being built. It also facilitates multiple developers
working on the same application at the same time by providing tools to resolve conflicts when they
arise. Xcode has built-in support for Git, one of the most popular SCM systems in use today. We
won’t be dealing with source control issues in this book, so it’s up to you to enable it or disable it,
whichever works for you.
After choosing whether to create a Git repository, create the new project by clicking the
Create button.
Figure 2-4. Saving your project in a project folder on your hard drive
18 CHAPTER 2: Appeasing the Tiki Gods
Even if you are an old hand with earlier versions of Xcode, you may still benefit from reading
through this section, since Apple has a habit of rearranging things and making improvements
from release to release. Let’s take a quick tour.
The Toolbar
The top of the Xcode project window is called the toolbar (see Figure 2-6). On the left side
of the toolbar are controls to start and stop running your project, as well as a pop-up menu
to select the scheme you want to run. A scheme brings together target and build settings,
and the toolbar pop-up menus lets you select a specific setup quickly and easily.
CHAPTER 2: Appeasing the Tiki Gods 19
The big box in the middle of the toolbar is the Activity View. As its name implies, the activity
view displays any actions or processes that are currently happening. For example, when you
run your project, the activity view gives you a running commentary on the various steps it’s
taking to build your application. If you encounter any errors or warnings, that information
is displayed here, as well. If you click the warning or error, you’ll go directly to the Issue
Navigator, which provides more information about the warning or error, as described in the
next section.
On the right side of the toolbar are two sets of buttons. The left set lets you switch between
three different editor configurations:
The Editor Area gives you a single pane dedicated to editing a file or
project-specific configuration values.
The incredibly powerful Assistant Editor splits the Editor Area into two
panes, left and right. The pane on the right is generally used to display
a file that relates to the file on the left, or that you might need to refer
to while editing the file on the left. You can manually specify what goes
into each pane, or you can let Xcode decide what’s most appropriate
for the task at hand. For example, if you’re designing your user interface
on the left, Xcode will show you the code that the user interface is
able to interact with on the right. You’ll see the Assistant Editor at work
throughout the book.
The Version Editor button converts the editor pane into a time
machine–like comparison view that works with version control systems
like Git. You can compare the current version of a source file with a
previously committed version or compare any two earlier versions with
each other.
To the right of the editor buttons is a set of toggle buttons that show and hide large panes
on the left and right sides of the editor view, as well as the debug area at the bottom of the
window. Click each of those buttons a few times to see these panes in action. You’ll learn
more about how these are used soon.
20 CHAPTER 2: Appeasing the Tiki Gods
The Navigator
Just below the toolbar, on the left side of the project window, is the Navigator. The
Navigator offers eight views that show you different aspects of your project. Click each of
the icons at the top of the navigator to switch among the following navigators, going from
left to right:
Project Navigator: This view contains a list of files in your project (see
Figure 2-7). You can store references to everything you expect—from
source code files to artwork, data models, property list (or .plist) files
(discussed in the “A Closer Look at Our Project” section later in this
chapter), and even other project files. By storing multiple projects in a
single workspace, those projects can easily share resources. If you click
any file in the navigator view, that file will display in the Editor Area. In
addition to viewing the file, you can also edit it (if it’s a file that Xcode
knows how to edit).
Figure 2-7. The Xcode Project Navigator. Click one of the eight icons at the top of the view to switch navigators
CHAPTER 2: Appeasing the Tiki Gods 21
Figure 2-8. The Xcode Symbol Navigator. Open the disclosure triangle to explore the classes, methods, and other
symbols defined within each group
22 CHAPTER 2: Appeasing the Tiki Gods
Figure 2-9. The Xcode Find Navigator. Be sure to check out the pop-up menus hidden under the word Find and under
the buttons that are below the search field
Other documents randomly have
different content
honour. Ben Jonson calls her ‘A tender mother, a discreet wife, a
solemn mistress, a good friend, so lovely and charitable in all her
petite actions, so devote in her whole life,’ etc.
Whatever Sir Kenelm’s real feelings were, his outward grief was
extreme. He retired to Gresham College, lived like a hermit, studied
chemistry, wore a long mourning cloak, and left his beard unshorn.
Although it was generally supposed that his secession from the
Protestant faith took place when he was in Spain, it was not until
1653 that he wrote to his friend Laud (whose admirable answer is
extant) to announce the fact. He was a firm adherent of Charles I.,
and greatly esteemed by Henrietta Maria; but his loyalty got him into
trouble with the Parliament, and he was exiled to France. Returning
in a few months he was imprisoned in 1640 for nearly three years,
and was supposed only to have regained his liberty through the
intercession of the French Queen, who had loved him twenty years
before. His release, however, was conditional. He was forbidden to
take part in any public affairs, and he therefore gave himself up to
literary and scientific pursuits, and engaged in a polemical
correspondence with his quondam tutor, Laud, whom he is said to
have tempted to change his faith, by the bait of a Cardinal’s Hat. Sir
Kenelm returned to France and frequented the Court of his old
flame, the Queen Dowager, where his noble appearance, almost
gigantic size, his handsome features, agreeable conversation and
manners, his learning, and last, but perhaps not least, his
predilection for the occult sciences, made him an universal favourite.
On the death of his eldest son, killed on the Royalist side at the
battle of St. Neot’s, Sir Kenelm returned to compound for his estates,
but was not suffered to remain in England. He went back to Paris,
where Henrietta Maria made him her Chancellor; and he was then
intrusted with a mission to Pope Innocent X., who welcomed him at
first, but after a time the ‘Englishman grew high, and hectored at His
Holiness, and gave him the lie.’
Once more in England, after the dissolution of the Long
Parliament, Cromwell took him into his confidence, hoping by his
mediation to gain over the Roman Catholics.
His conduct in these circumstances has been praised by some and
censured by others, as may well be imagined, according to religious
and political bias. He travelled through France, Lower Germany, and
the Palatinate, always seeking and being sought by men of letters;
and 1660 saw him once more back in his native land.
Charles II. showed him but little favour. He was nominated F.R.S.,
and resided (1663) in a fair house in Covent Garden, where he had a
laboratory. ‘Philosopher, theologian, courtier, soldier; polite, amiable,
handsome, graceful.’ Lord Clarendon’s testimony is, ‘eccentric, vain,
unstable in religion, a duellist.’ These are the counterbalancing
portraits of Sir Kenelm Digby. He desired to be buried near Venetia.
His epitaph was as follows:—
‘Under this tomb the matchless Digby lies,
Digby the great, the brilliant, and the wise;
This age’s wonder, for his noble partes,
Skilled in six tongues, and learn’d in all the artes!
Born on the day he died, th’ eleventh of June,
And that day bravely fought at Scanderoon:
It’s rare that one and the same day should be
The day of birth, and death, and victory.’
By Vandyck.
DIED 1627.
By Zucchero.
By Holbein.
By Vandyck.
M
istress Cecilia Crofts, maid of honour to the Queen Henrietta
Maria?
PRINCIPAL STAIRCASE.
PRINCIPAL STAIRCASE.
No. 1. GRACE, COUNTESS OF DYSART.
Pale yellow dress. Leaning her elbow on a table.
DIED 1744.
By Wright.
By Wright.
By Riley.
By Jansen.
ebookgate.com