Professional Documents
Culture Documents
Textbook Ios 11 by Tutorials Learning The New Ios Apis With Swift 4 1St Edition The Raywenderlich Tutorial Team Ebook All Chapter PDF
Textbook Ios 11 by Tutorials Learning The New Ios Apis With Swift 4 1St Edition The Raywenderlich Tutorial Team Ebook All Chapter PDF
https://textbookfull.com/product/machine-learning-by-tutorials-
beginning-machine-learning-for-apple-and-ios-first-edition-
raywenderlich-tutorial-team/
https://textbookfull.com/product/ios-apprentice-eighth-edition-
beginning-ios-development-with-swift-and-uikit-raywenderlich-
tutorial-team/
https://textbookfull.com/product/design-patterns-by-tutorials-
third-edition-learning-design-patterns-in-swift-raywenderlich-
tutorial-team/
https://textbookfull.com/product/learn-ios-11-programming-with-
swift-4-craig-clayton/
RxSwift Reactive Programming with Swift Third Edition
Raywenderlich Tutorial Team
https://textbookfull.com/product/rxswift-reactive-programming-
with-swift-third-edition-raywenderlich-tutorial-team/
https://textbookfull.com/product/concurrency-by-tutorials-second-
edition-multithreading-in-swift-with-gcd-and-operations-tutorial-
team/
https://textbookfull.com/product/ios-11-swift-programming-
cookbook-solutions-and-examples-for-ios-apps-1st-edition-vandad-
nahavandipoor/
https://textbookfull.com/product/ios-11-programming-fundamentals-
with-swift-swift-xcode-and-cocoa-basics-4th-edition-matt-neuburg/
Server Side Swift with Vapor Building Web APIs and Web
Apps in Swift 3rd Edition Raywenderlich.Com Tutorial
Team
https://textbookfull.com/product/server-side-swift-with-vapor-
building-web-apis-and-web-apps-in-swift-3rd-edition-
raywenderlich-com-tutorial-team/
iOS 11 by Tutorials
iOS 11 by Tutorials
Jeff Rames, Andy Pereira, Michael Katz, Richard Critz, Jawwad Ahmad, Michael Ciurus,
Mic Pringle & Jerry Beers
Notice of Rights
All rights reserved. No part of this book or corresponding materials (such as text,
images, or source code) may be reproduced or distributed by any means without prior
written permission of the copyright owner.
Notice of Liability
This book and all corresponding materials (such as source code) are provided on an “as
is” basis, without warranty of any kind, express of implied, including but not limited to
the warranties of merchantability, fitness for a particular purpose, and
noninfringement. In no event shall the authors or copyright holders be liable for any
claim, damages or other liability, whether in action of contract, tort or otherwise,
arising from, out of or in connection with the software or the use of other dealing in the
software.
Trademarks
All trademarks and registered trademarks appearing in this book are the property of
their own respective owners.
raywenderlich.com 2
iOS 11 by Tutorials
raywenderlich.com 3
iOS 11 by Tutorials
Andy Pereira is a senior iOS developer with Delta Air Lines. When
he’s not coding, he’s spending time traveling the world with his wife,
and playing guitar.
Chris Belanger (Editor): Chris is the Book Team Lead and Lead Editor
for raywenderlich.com. He was a developer for nearly 20 years in
various fields from e-health to aerial surveillance to industrial
controls. If there are words to wrangle or a paragraph to ponder, he‘s
on the case. When he kicks back, you can usually find Chris with
guitar in hand, looking for the nearest beach. Twitter: @crispytwit
raywenderlich.com 4
iOS 11 by Tutorials
Kyle Gorlick (Technical Editor): Kyle creates mobile apps and games.
He likes to play volleyball and watch basketball. More info at
kylegorlick.com.
raywenderlich.com 5
iOS 11 by Tutorials
raywenderlich.com 6
iOS 11 by Tutorials
raywenderlich.com 7
iOS 11 by Tutorials
raywenderlich.com 8
iOS 11 by Tutorials
raywenderlich.com 9
iOS 11 by Tutorials
raywenderlich.com 10
iOS 11 by Tutorials
raywenderlich.com 11
iOS 11 by Tutorials
raywenderlich.com 12
I Introduction
Each year at WWDC, Apple introduces brand new tools and APIs for iOS developers.
WWDC 2017 was no different, as iOS 11 and Xcode 9 introduced a pile of amazing new
technologies and features for developers of all backgrounds!
The most exciting feature in iOS 11 by far is ARKit, which opens up the world of
augmented reality to iPhone developers everywhere. Sure, it was possible to do some
basic AR on the iPhone before iOS 11, but ARKit does the heavy lifting of plane
detection and camera placement for you, so you can focus on building amazing
experiences instead. ARKit makes it easier than ever to create incredibly immersive
experiences, including portals to virtual worlds, 3D games and art, and compelling
ecommerce apps. What new worlds will you create with ARKit?
The new Vision and Core ML frameworks bring the power of machine learning models
into your apps. Whether you’re building a sentiment analysis app, creating advanced
face and scene detection algorithms, or just trying to figure out whether something is a
hot dog or not, Core ML makes it easy to plug pre-trained machine learning models into
your app, and Vision provides a host of advanced detection technologies for text,
images, faces, and more.
Xcode 9 sports a completely rewritten editor, helpers for code refactoring, improved
responsiveness, support for Markdown, and (finally!) wireless debugging. Add in the
other new features in iOS 11, such as the new drag-and-drop, PDFKit, MusicKit, Swift 4
updates and more, and you have one of the most exciting iOS releases to date.
Gone are the days when every third-party developer knew everything there is to know
about iOS. The sheer size of iOS can make new releases seem daunting. That’s why the
Tutorial Team has been working really hard to extract the important parts of the new
APIs, and to present this information in an easy-to-understand tutorial format. This
means you can focus on what you want to be doing — building amazing apps!
raywenderlich.com 13
iOS 11 by Tutorials Introduction
Get ready for your own private tour through the amazing new features of iOS 11. By the
time you’re done, your iOS knowledge will be completely up-to-date and you’ll be able
to benefit from the amazing new opportunities in iOS 11.
• A Mac running macOS Sierra or later. You’ll need this to be able to install the
latest version of Xcode.
• Xcode 9.0 or later. Xcode is the main development tool for iOS. You’ll need Xcode
9.0 or later for all tasks in this book. You can download the latest version of Xcode 9
beta on Apple’s developer site here: apple.co/2asi58y
• One or more devices (iPhone, iPad) running iOS 11 or later. Most of the chapters
in the book let you run your code on the iOS 11 Simulator that comes with Xcode.
However, a few chapters later in the book require one or more physical iOS devices
for testing. For ARKit chapters, you’ll need a device with an A9 processor or better.
Once you have these items in place, you’ll be able to follow along with every chapter in
this book.
• If you are a beginner to Swift, we recommend you read through either The iOS
Apprentice, Fifth Edition (if you are a complete beginner to programming), or The
Swift Apprentice, Second Edition (if you already have some programming experience)
first.
If you need one of these prerequisite books, you can find them on our store here:
• store.raywenderlich.com
raywenderlich.com 14
iOS 11 by Tutorials Introduction
Whatʼs in store
Here’s a quick summary of what you’ll find in each chapter:
Chapter 1, What’s New in Swift 4: Swift 4 shows a maturing of the Swift language,
and brings new functionality to Strings, improvements to Dictionaries and Sets, the
new Codable protocol, multi-line string literals, one-sided ranges and more. Read this
chapter for a quick overview of what’s new!
Chapter 2, What’s New in Foundation: Learn about all the best updates under the
hood, including updates to the FileProvider API, key paths, encoding and decoding, and
more.
Chapter 4, What’s New in UIKit: This chapter covers the best new UI features of iOS
11, such as Drag and Drop, the Document Browser, table view changes, and changes to
Auto Layout.
Chapter 5, What’s New in Layout: Expanding upon the previous chapter, you’ll
explore the way Auto Layout works in iOS 11, including changes to navigation
controllers, large titles, safe areas, table views, stack views, and more.
Chapter 6, Beginning Drag and Drop: Take advantage of the new drag-and-drop
features to select one or more files from within your application, drag them around, and
drop them on target locations within your app.
Chapter 7, Advanced Drag and Drop: Building on the previous chapter, you’ll explore
how to drag and drop files between different applications, how NSItemProvider and
UIDragItem work, and how to animate your drag-and-drop in intelligent, meaningful
ways.
Chapter 8, Document-Based Apps: Learn how the Document Provider works, how it
stands apart from the Document Picker, how to create new files, import existing files,
and even add custom actions.
Chapter 9, Core ML & Vision: Get started with the exciting Core ML and Vision
frameworks as you build a face-detection and text-recognition app, complete with
filters and object classification.
raywenderlich.com 15
iOS 11 by Tutorials Introduction
Chapter 10, Natural Language Processing: Learn how to detect the language of a
body of text, how to work with named entities, how sentiment analysis works, how to
perform searches with NSLinguisticTagger, and more!
Chapter 11, ARKit: Build your own augmented reality app as you learn how to set up
ARKit, detect feature points and draw planes, how to create and locate 3D models in
your scene, handle low lighting conditions and manage session interruptions. With all
the amazing things happening in AR lately, you won’t want to miss this chapter!
Chapter 12, PDFKit: Finally — you can easily create and annotate PDFs using native
Apple libraries on the iPhone with PDFKit. Learn how to create thumbnails, add text, UI
controls and watermarks to your documents, and even create custom actions for the UI
controls in your PDF documents.
Chapter 13, MusicKit: Enjoy your vast collection of songs in Apple Music — directly in
your own apps! You’ll create a fun song-guessing game to play with your friends as you
learn how to select, share and play music from your library, manage access permissions
and even detect when a user isn’t a member of Apple Music and encourage them to sign
up.
Chapter 14, Password Autofill: A vast improvement on iOS 8’s Safari Autofill, the new
password autofilling option in iOS 11 makes it easier for your users to log in to your
app, while maintaining user confidentiality at all times. Learn how to auto-recognize
username and password fields, set up associated domains, and create a seamless login
experience for your users.
Chapter 15, Dynamic Type: Dynamic type is even better in iOS 11 — less truncation
and clipping, improved titles on tab bars, and more intelligent scaling make using text
onscreen a breeze. Learn how to think about Dynamic Type as you architect your app,
and how to accommodate large typefaces in your app’s layout.
We’ve also set up an official forum for the book at forums.raywenderlich.com. This is a
great place to ask questions about the book, discuss making apps with iOS 11 in
general, share challenge solutions, or to submit any errors you may find.
raywenderlich.com 16
iOS 11 by Tutorials Introduction
Book updates
Great news: since you purchased the PDF version of this book, you’ll receive free
updates of the content in this book!
The best way to receive update notifications is to sign up for our weekly newsletter. This
includes a list of the tutorials published on raywenderlich.com in the past week,
important news items such as book updates or new books, and a few of our favorite
developer links. You can sign up here:
• www.raywenderlich.com/newsletter
License
By purchasing iOS 11 by Tutorials, you have the following license:
• You are allowed to use and/or modify the source code in iOS 11 by Tutorials in as
many apps as you want, with no attribution required.
• You are allowed to use and/or modify all art, images, or designs that are included in
iOS 11 by Tutorials in as many apps as you want, but must include this attribution
line somewhere inside your app: “Artwork/images/designs: from the iOS 11 by
Tutorials book, available at www.raywenderlich.com”.
• The source code included in iOS 11 by Tutorials is for your own personal use only. You
are NOT allowed to distribute or sell the source code in iOS 11 by Tutorials without
prior authorization.
• This book is for your own personal use only. You are NOT allowed to sell this book
without prior authorization, or distribute it to friends, co-workers, or students; they
must to purchase their own copy instead.
All materials provided with this book are provided on an “as is” basis, without warranty
of any kind, express or implied, including but not limited to the warranties of
merchantability, fitness for a particular purpose and non-infringement. In no event
shall the authors or copyright holders be liable for any claim, damages or other liability,
whether in an action of contract, tort or otherwise, arising from, out of or in connection
with the software or the use or other dealings in the software.
All trademarks and registered trademarks appearing in this guide are the property of
their respective owners.
raywenderlich.com 17
iOS 11 by Tutorials Introduction
Acknowledgments
We would like to thank many people for their assistance in making this possible:
• Our families: For bearing with us in this crazy time as we worked all hours of the
night to get this book ready for publication!
• Everyone at Apple: For developing an amazing operating system and set of APIs, for
constantly inspiring us to improve our apps and skills, and for making it possible for
many developers to have their dream jobs!
Surgeonfish get their name from the sharp, venomous scalpel-like spines on their body
that they use to fight off predators, and sometimes, each other. Although they can
defend themselves, surgeonfish often float motionless on their side and “play dead” to
avoid being detected by larger, passing predators.
However, we don’t recommend that same approach to avoid being detected by your
boss, when you’re spending all your work hours building cool ARKit apps!
raywenderlich.com 18
1 Chapter 1: Whatʼs New in
Swift 4
By Richard Critz
If last year’s changes for Swift 3 still cause you uncontrollable night terrors, you’re in
for a pleasant surprise with Swift 4. By comparison, the changes in Swift 4 are much
more modest and even bring back some old capabilities, in new and improved form.
Even better, you don’t have to update right away!
The Swift 4 compiler integrated into Xcode 9 has a “Swift 3.2” mode. This is not a
separate compiler, but a mode that allows you to continue building your Swift 3 sources
so you can update to Swift 4 on your schedule. Your favorite CocoaPod has not yet been
updated? No problem. You can select your Swift language version on a per-target basis
in your project, so you can mix Swift 3 and Swift 4 targets in the same project.
Note: Since Swift is an open source project, each change must go through the
“Swift Evolution” process. This process involves the Swift Community working
together to propose, discuss and review new ideas to help improve the language.
Each proposal is numbered and made publicly available at https://github.com/
apple/swift-evolution/tree/master/proposals.
raywenderlich.com 19
iOS 11 by Tutorials Chapter 1: What’s New in Swift 4
At the the beginning of each section in this chapter is the number(s) of the
proposal(s) that instigated the changes — just in case you’re interested in the gory
details.
One-sided ranges
[SE-0172]
This can be really useful when you want to extract the beginning or ending of a
collection.
esports[3...]
// returns ["Super Smash Bros", "Overwatch", "Gigantic"]
esports[...2]
// returns ["Hearthstone", "CS:GO", "League of Legends"]
esports[..<2]
// returns ["Hearthstone", "CS:GO"]
Infinite sequences
A one-sided range can be used to create an infinite sequence, one where only the
beginning is defined. For example, you can build an array of tuples matching the
decimal ASCII code of a character with the character itself.
raywenderlich.com 20
iOS 11 by Tutorials Chapter 1: What’s New in Swift 4
Pattern matching
A one-sided range can greatly simplify the patterns for a switch statement.
gameRank(2)
// prints "Awesome-sauce!"
sentiment(0.5)
// returns "
Strings
[SE-0162, SE-0168, SE-0178, SE-0182, SE-0183]
Strings received a lot of love in Swift 4, and all of that attention made them more
powerful and easier to use. The most significant change is that Strings are now
Collections, like they were in Swift 1. This means that all the fancy things that a
Collection can do, a String can do too!
raywenderlich.com 21
iOS 11 by Tutorials Chapter 1: What’s New in Swift 4
text.count // 13
text.isEmpty // false
"".isEmpty // true
It’s easy to iterate through each character in a string, and it works properly for Unicode
characters as well.
for c in unicodeText {
print(c) // prints each of 8 characters, one to a line
}
String subscripts are not primitive types such as Int. Instead, they must be either a
String.Index or Range<String.Index>.
Introducing Substring
Swift tries to be efficient when managing the buffers associated with strings. As such,
subscripting operations return a view of portion of the original string’s buffer,
incrementing that buffer’s reference count. Depending on the application and its data,
this has the potential to keep large, unused portions of strings in memory. While this
technically isn’t a memory leak, it will look, smell and quack a lot like one.
The Swift standard library solves this by introducing a new type: Substring, returned by
string subscripting operations. Most APIs will continue to use String parameters and
you must explicitly create a new String from the Substring to use them. This allows
the original, larger string to go out-of-scope naturally and be deallocated.
This is not as unpleasant as it first may seem, because the standard library also
introduces a new protocol: StringProtocol. Most of the String API is moved into
StringProtocol, and both String and Substring conform to this new protocol.
raywenderlich.com 22
iOS 11 by Tutorials Chapter 1: What’s New in Swift 4
type(of: lastWord)
// Substring.Type
lastWord.uppercased()
// "MATATA"
Note: Option-clicking a variable name such as lastWord in Xcode to see its type
will get the answer String.Subsequence. This is simply a typealias for Substring.
type(of: lastWord) does, in fact, return Substring.Type.
Unicode magic
If you wanted to access the individual Unicode values of a Character in Swift 3, you first
had to convert it to String. Now, Character has a unicodeScalars property.
Swift 3 didn’t like any of the following expressions, giving the wrong answer in each
case. Swift 4, on the other hand, handles them correctly, giving the expected length
based on what you see rather than what’s required to encode it.
"( * + ".count // 3
"$ ".count // 1
"% ".count // 1
"' ".count // 1
And, as you saw earlier, iterating through a string shows each Unicode character
correctly.
raywenderlich.com 23
iOS 11 by Tutorials Chapter 1: What’s New in Swift 4
population.utf16.count
// 29
As expected, the length of the NSRange matches the length of the UTF-16 view. display
looks like this:
The above finds the indices of each of the number badges, creates a range
(Range<String.Index>) for the first part of the string and converts it to an NSRange.
Then, it applies a new font attribute and now display looks like this:
range = twoIndex..<threeIndex
nsRange = NSRange(range, in: population)
display.addAttribute(.font,
value: UIFont.systemFont(ofSize: 30),
range: nsRange)
raywenderlich.com 24
iOS 11 by Tutorials Chapter 1: What’s New in Swift 4
Next, this code makes the range represent the middle section of the string, converts it
to NSRange and applies another new font attribute. Now display looks like this:
It’s just as easy to go the other way and create a Range<String.Index> from an NSRange.
Note that this initializer is failable, so the result is an optional.
The literal is delimited by """ and the indentation of the closing delimiter determines
how much whitespace is stripped from the beginning of each line. You can use quotes in
the literal without escaping them.
raywenderlich.com 25
iOS 11 by Tutorials Chapter 1: What’s New in Swift 4
Dictionary enhancements
[SE-0165]
As a Swift programmer, you know how important Dictionary is to your daily life. Swift 4
brings a number of improvements to make it even more powerful, useful and usable.
Sequence-based initializer
You can now create dictionaries from a sequence of key-value pairs. For example, you
can create a numbered list of items.
raywenderlich.com 26
iOS 11 by Tutorials Chapter 1: What’s New in Swift 4
Merging
Dictionary now includes an initializer that allows you to merge two dictionaries
together. If you want to merge one dictionary into another, Swift also provides a merge
method. Both allow you to specify a closure to resolve merge conflicts caused by
duplicate keys.
let duplicates = [("a", 1), ("b", 2), ("a", 3), ("b", 4)]
let oldest = Dictionary(duplicates) { (current, _) in
current
}
// ["b": 2, "a": 1]
You can take advantage of the closure to transform your input. Here’s a more powerful
example that takes an array of key-value pairs and turns them into a dictionary of
arrays:
let sortingHat = [
("Gryffindor", "Harry Potter"), ("Slytherin", "Draco Malfoy"),
("Gryffindor", "Ron Weasley"),
("Slytherin", "Pansy Parkinson"),
("Gryffindor", "Hermione Granger"),
("Hufflepuff", "Hannah Abbott"),
("Ravenclaw", "Terry Boot"), ("Hufflepuff", "Susan Bones"),
("Ravenclaw", "Lisa Turpin"),
("Gryffindor", "Neville Longbottom")
]
let houses = Dictionary(
sortingHat.map { ($0.0, [$0.1]) },
uniquingKeysWith: { (current, new) in
return current + new
})
// ["Ravenclaw": ["Terry Boot", "Lisa Turpin"],
// "Hufflepuff": ["Hannah Abbott", "Susan Bones"],
// "Slytherin": ["Draco Malfoy", "Pansy Parkinson"],
// "Gryffindor": ["Harry Potter", "Ron Weasley",
// "Hermione Granger", "Neville Longbottom"]]
As you can see, you can do far more than just create a dictionary. Suppose you want to
know how often each letter occurs in a string? Dictionary merging is on the case!
raywenderlich.com 27
iOS 11 by Tutorials Chapter 1: What’s New in Swift 4
If you have a set of defaults and wish to combine them with user settings, this is a
perfect use for the merge method.
This is a sufficiently common practice that Swift 4 adds the ability to specify the default
value right in the subscript.
The default subscript provides another way to implement the frequency counter you
saw earlier.
frequencies.removeAll()
spell.filter { $0 != " " }.map {
frequencies[$0, default: 0] += 1
}
// produces the same results as before
raywenderlich.com 28
iOS 11 by Tutorials Chapter 1: What’s New in Swift 4
The map function always returns an Array. Frequently, when working with a dictionary,
this is precisely not what you want! Swift 4 adds mapValue to allow you to retain the
dictionary’s structure and type.
Grouping
One of Dictionary’s most powerful new features is the ability is partition your data
based on an arbitrary predicate, creating groups or buckets of similar data.
The fact that you can specify an arbitrary predicate lets you get more creative.
enum Multiples {
case threes, notThrees
}
let numbers = 1...18
let predicate: (Int) -> Multiples =
{ $0 % 3 == 0 ? .threes : .notThrees }
let multiplesOfThree = Dictionary(grouping: numbers,
by: predicate)
// [.threes: [3, 6, 9, 12, 15, 18],
// [.notThrees: [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17]]
type(of: multiplesOfThree)
// [Multiples: [Int]]
raywenderlich.com 29
Another random document with
no related content on Scribd:
Abstracts from the Text of Senator Miller’s
Speech.
On his Bill to Prohibit Chinese Immigration.
In the Senate, Feb. 28th, 1882, Mr. Miller said:
“This measure is not a surprise to the Senate, nor a new revelation
to the country. It has been before Congress more than once, if not in
the precise form in which it is now presented, in substance the same,
and it has passed the ordeal of analytical debate and received the
affirmative vote of both Houses. Except for the Executive veto it
would have been long ago the law of the land. It is again presented,
not only under circumstances as imperative in their demands for its
enactment, but with every objection of the veto removed and every
argument made against its approval swept away. It is an interesting
fact in the history of this measure, that the action which has cleared
its way of the impediments which were made the reasons for the
veto, was inaugurated and consummated with splendid persistence
and energy by the same administration whose executive interposed
the veto against it. Without stopping to inquire into the motive of the
Hayes administration in this proceeding, whether its action was in
obedience to a conviction that the measure was in itself right and
expedient, or to a public sentiment, so strong and universal as to
demand the utmost vigor in the diplomacy necessary for the removal
of all impediments to its progress, it must be apparent that the result
of this diplomatic action has been to add a new phase to the question
in respect of the adoption of the measure itself.
“In order to fully appreciate this fact it may be proper to indulge in
historical reminiscence for a moment. For many years complaints
had been made against the introduction into the United States of the
peculiar people who come from China, and the Congress, after
careful consideration of the subject, so far appreciated the evil
complained of as to pass a bill to interdict it.
“The Executive Department had, prior to that action, with
diplomatic finesse, approached the imperial throne of China, with
intent, as was said, to ascertain whether such an interdiction of
coolie importation, or immigration so called, into the United States
would be regarded as a breach of friendly relations with China, and
had been informed by the diplomat, to whom the delicate task had
been committed, that such interdiction would not be favorably
regarded by the Chinese Government. Hence, when Congress, with
surprising audacity, passed the bill of interdiction the Executive,
believing in the truth of the information given him, thought it
prudent and expedient to veto the bill, but immediately, in
pursuance of authority granted by Congress, he appointed three
commissioners to negotiate a treaty by which the consent of China
should be given to the interdiction proposed by Congress. These
commissioners appeared before the Government of China upon this
special mission, and presented the request of the Government of the
United States affirmatively, positively, and authoritatively made, and
after the usual diplomatic ceremonies, representations,
misrepresentations, avowals, and concealments, the treaty was
made, the concession granted, and the interdiction agreed upon. This
treaty was presented here and ratified by the Senate, with what
unanimity Senators know, and which the rules of the Senate forbid
me to describe.
“The new phase of this question, which we may as well consider in
the outset, suggests the spectacle which this nation should present if
Congress were to vote this or a similar measure down. A great nation
cannot afford inconsistency in action, nor betray a vacillating,
staggering, inconstant policy in its intercourse with other nations. No
really great people will present themselves before the world through
their government as a nation irresolute, fickle, feeble, or petulant;
one day eagerly demanding of its neighbor an agreement or
concession, which on the next it nervously repudiates or casts aside.
Can we make a solemn request of China, through the pomp of an
extraordinary embassy and the ceremony of diplomatic negotiation,
and with prudent dispatch exchange ratifications of the treaty
granting our request, and within less than half a year after such
exchange is made cast aside the concession and, with childish
irresolution, ignore the whole proceeding? Can we afford to make
such a confession of American imbecility to any oriental power? The
adoption of this or some such measure becomes necessary, it seems
to me, to the intelligent and consistent execution of a policy adopted
by this Government under the sanction of a treaty with another great
nation.
“If the Executive department, the Senate, and the House of
Representatives have all understood and appreciated their own
action in respect of this measure; if in the negotiation and
ratification of the new treaty with China, the Executive and the
Senate did not act without thought, in blind, inconsiderate
recklessness—and we know they did not—if the Congress of the
United States in the passage of the fifteen passenger bill had the
faintest conception of what it was doing—and we know it had—then
the policy of this Government in respect of so-called Chinese
immigration has been authoritatively settled.
“This proposition is submitted with the greater confidence because
the action I have described was in obedience to, and in harmony
with, a public sentiment which seems to have permeated the whole
country. For the evidence of the existence of such a sentiment, it is
only necessary to produce the declarations upon this subject of the
two great historical parties of the country, deliberately made by their
national conventions of 1880. One of these (the Democratic
convention) declared that there shall be—
“‘No more Chinese immigration except for travel, education, and
foreign commerce, and therein carefully guarded.’
“The other (the Republican) convention declared that—
“‘Since the authority to regulate immigration and intercourse
between the United States and foreign nations rests with Congress,
or with the United States and its treaty-making power, the
Republican party, regarding the unrestricted immigration of the
Chinese as an evil of great magnitude, invokes the exercise of these
powers to restrain and limit the immigration by the enactment of
such just, humane, and reasonable provisions as will produce that
result.’
“These are the declarations of the two great political parties, in
whose ranks are enrolled nearly all the voters of the United States;
and whoever voted at the last Presidential election voted for the
adoption of the principles and policy expressed by those
declarations, whether he voted with the one or the other of the two
great parties. Both candidates for the Presidency were pledged to the
adoption and execution of the policy of restriction thus declared by
their respective parties, and the candidate who was successful at the
polls, in his letter of acceptance, not only gave expression to the
sentiment of his party and the country, but with a clearness and
conciseness which distinguished all his utterances upon great public
questions, gave the reasons for that public sentiment.” He said:
“‘The recent movement of the Chinese to our Pacific Coast
partakes but little of the qualities of an immigration, either in its
purposes or results. It is too much like an importation to be
welcomed without restriction; too much like an invasion to be looked
upon without solicitude. We cannot consent to allow any form of
servile labor to be introduced among us under the guise of
immigration.’
“If you would ‘secure the blessings of liberty to ourselves and our
posterity,’ there must be some place reserved in which, and upon
which, posterity can exist. What will the blessings of liberty be worth
to posterity if you give up the country to the Chinese? If China is to
be the breeding-ground for peopling this country, what chance of
American posterity? We of this age hold this land in trust for our race
and kindred. We hold republican government and free institutions in
trust for American posterity. That trust ought not to be betrayed. If
the Chinese should invade the Pacific coast with arms in their hands,
what a magnificent spectacle of martial resistance would be
presented to a startled world! The mere intimation of an attempt to
make conquest of our western shore by force would rouse the nation
to a frenzy of enthusiasm in its defense. For years a peaceful, sly,
strategic conquest has been in progress, and American
statesmanship has been almost silent, until the people have
demanded action.
“The land which is being overrun by the oriental invader is the
fairest portion of our heritage. It is the land of the vine and the fig
tree; the home of the orange, the olive, and the pomegranate. Its
winter is a perpetual spring, and its summer is a golden harvest.
There the northern pine peacefully sways against the southern palm;
the tender azalea and the hardy rose mingle their sweet perfume, and
the tropic vine encircles the sturdy oak. Its valleys are rich and
glorious with luscious fruits and waving grain, and its lofty
Mountains like giants stand,
To sentinel the enchanted land.
“I would see its fertile plains, its sequestered vales, its vine-clad
hills, its deep blue canons, its furrowed mountain-sides, dotted all
over with American homes—the homes of a free, happy people,
resonant with the sweet voices of flaxen-haired children, and ringing
with the joyous laughter of maiden fair—
Soft as her clime, and sunny as her skies—
like the homes of New England; yet brighter and better far shall be
the homes which are to be builded in that wonderland by the sunset
sea, the homes of a race from which shall spring
The flower of men,
To serve as model for the mighty world,
And be the fair beginning of a time.”
Reply of Senator Geo. P. Hoar.
DECLARATION OF RIGHTS.
Section 1. All men are by nature free and independent, and have
certain inalienable rights, among which are those of enjoying and
defending life and liberty, acquiring, possessing, and defending
property, and pursuing and obtaining safety and happiness.
Sec. 17. Foreigners who are or who may hereafter become bona
fide residents of this State, shall enjoy the same rights in respect to
the possession, enjoyment, and inheritance of property, as native-
born citizens.
In the Revised Statutes, section 1999, Congress in the most solemn
manner declare that the right of expatriation is beyond the lawful
control of government:
Sec. 1999. Whereas the right of expatriation is a natural and
inherent right of all people, indispensable to the enjoyment of the
rights of life, liberty, and the pursuit of happiness; and
Whereas in the recognition of this principle this Government has
freely received emigrants from all nations, and invested them with
the rights of citizenship.
This is a re-enactment, in part, of the statute of 1868, of which Mr.
Conness, then a California Senator, of Irish birth, was, if not the
author, the chief advocate.
The California Senator called up the bill day after day. The bill
originally provided that the President might order the arrest and
detention in custody of “any subject or citizen of such foreign
government” as should arrest and detain any naturalized citizen of
the United States under the claim that he still remained subject to his
allegiance to his native sovereign. This gave rise to debate.
But there was no controversy about the part of the bill which I
have read. The preamble is as follows:
Whereas the right of expatriation is a natural and inherent right of
all people, indispensable to the enjoyment of the rights of life, liberty,
and the pursuit of happiness, for the protection of which the
Government of the United States was established; and whereas in the
recognition of this principle this Government has freely received
emigrants from all nations and vested them with the rights of
citizenship, &c.
Mr. Howard declares that—
The absolute right of expatriation is the great leading American
principle.
Mr. Morton says:
That a man’s right to withdraw from his native country and make
his home in another, and thus cut himself off from all connection
with his native country, is a part of his natural liberty, and without
that his liberty is defective. We claim that the right to liberty is a
natural, inherent, God-given right, and his liberty is imperfect unless
it carries with it the right of expatriation.
The bill containing the preamble above recited passed the Senate
by a vote of 39 to 5.
The United States of America and the Emperor of China cordially
recognize the inherent and inalienable right of man to change his
home and allegiance, and also the mutual advantage of the free
migration and emigration of their citizens and subjects respectively
from the one country to the other for purposes of curiosity, of trade,
or as permanent residents.
“The bill which passed Congress two years ago and was vetoed by
President Hayes, the treaty of 1881, and the bill now before the
Senate, have the same origin and are parts of the same measure. Two
years ago it was proposed to exclude Chinese laborers from our
borders, in express disregard of our solemn treaty obligations. This
measure was arrested by President Hayes. The treaty of 1881
extorted from unwilling China her consent that we might regulate,
limit, or suspend the coming of Chinese laborers into this country—a
consent of which it is proposed by this bill to take advantage. This is
entitled “A bill to enforce treaty stipulations with China.”
“It seems necessary in discussing the statute briefly to review the
history of the treaty. First let me say that the title of this bill is
deceptive. There is no stipulation of the treaty which the bill
enforces. The bill where it is not inconsistent with the compact only
avails itself of a privilege which that concedes. China only relaxed the
Burlingame treaty so far as to permit us to ‘regulate, limit, or
suspend the coming or residence’ of Chinese laborers, ‘but not
absolutely to prohibit it.’ The treaty expressly declares ‘such
limitation or suspension shall be reasonable.’ But here is proposed a
statute which for twenty years, under the severest penalties,
absolutely inhibits the coming of Chinese laborers to this country.
The treaty pledges us not absolutely to prohibit it. The bill is
intended absolutely to prohibit it.
“The second article of the treaty is this:
“Chinese subjects, whether proceeding to the United States as
traders, students, or merchants, or from curiosity, together with their
body and household servants, and Chinese laborers, who are now in
the United States, shall be allowed to go and come of their own free
will and accord, and shall be accorded all the rights, privileges,
immunities, and exemptions which are accorded to the citizens and
subjects of the most favored nations.
“Yet it is difficult to believe that the complex and cumbrous
passport system provided in the last twelve sections of the bill was
not intended as an evasion of this agreement. Upon what other
nation, favored or not, is such a burden imposed? This is the
execution of a promise that they may come and go ‘of their own free
will.’
“What has happened within thirteen years that the great Republic
should strike its flag? What change has come over us that we should
eat the bravest and the truest words we ever spoke? From 1858 to
1880 there was added to the population of the country 42,000
Chinese.
“I give a table from the census of 1880 showing the Chinese
population of each State:
Statement showing the Chinese population in each State and
Territory, according to the United States censuses of 1870 and of
1880.
Alabama 4
Alaska
Arizona 20 1,630
Arkansas 98 134
California 49,310 75,025
Colorado 7 610
Connecticut 2 124
Dakota 238
Delaware 1
District of Columbia 3 13
Florida 18
Georgia 1 17
Idaho 4,274 3,378
Illinois 1 210
Indiana 33
Iowa 3 47
Kansas 19
Kentucky 1 10
Louisiana 71 481
Maine 1 9
Maryland 2 5
Massachusetts 97 237
Michigan 2 27
Minnesota 53
Mississippi 16 52
Missouri 3 94
Montana 1,949 1,764
Nebraska 18
Nevada 3,152 5,420
New Hampshire 14
New Jersey 15 176
New Mexico 55
New York 29 924
North Carolina
Ohio 1 114
Oregon 3,330 9,513
Pennsylvania 14 160
Rhode Island 27
South Carolina 1 9
Tennessee 26
Texas 25 141
Utah 445 501
Vermont
Virginia 4 6
Washington 234 3,182
West Virginia 14
Wisconsin 16
Wyoming 143 914
“By the census of 1880 the number of Chinese in this country was
105,000—one five-hundredth part of the whole population. The
Chinese are the most easily governed race in the world. Yet every
Chinaman in America has four hundred and ninety-nine Americans
to control him.
The immigration was also constantly decreasing for the last half of
the decade. The Bureau of Statistics gives the numbers as follows,
(for the first eight years the figures are those of the entire Asiatic
immigration:)
The number of immigrants from Asia, as reported by the United
States Bureau of Statistics is as follows, namely:
1871 7,236
1872 7,825
1873 20,326
1874 13,857
1875 16,498
1876 22,943
1877 10,640
1878 9,014
Total 108,339
1879 9,604
1880 5,802
Total 15,406