100% found this document useful (2 votes)
3 views

iOS 12 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 5th Edition Matt Neuburg pdf download

Ebook download

Uploaded by

jayedmonotbp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
3 views

iOS 12 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 5th Edition Matt Neuburg pdf download

Ebook download

Uploaded by

jayedmonotbp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

iOS 12 Programming Fundamentals with Swift Swift

Xcode and Cocoa Basics 5th Edition Matt Neuburg


download

https://textbookfull.com/product/ios-12-programming-fundamentals-
with-swift-swift-xcode-and-cocoa-basics-5th-edition-matt-
neuburg-3/

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

iOS 12 Programming Fundamentals with Swift Swift Xcode


and Cocoa Basics 5th Edition Matt Neuburg

https://textbookfull.com/product/ios-12-programming-fundamentals-
with-swift-swift-xcode-and-cocoa-basics-5th-edition-matt-
neuburg-2/

iOS 12 Programming Fundamentals with Swift Swift Xcode


and Cocoa Basics 5th Edition Matt Neuburg

https://textbookfull.com/product/ios-12-programming-fundamentals-
with-swift-swift-xcode-and-cocoa-basics-5th-edition-matt-
neuburg-3/

iOS 10 Programming Fundamentals with Swift Swift Xcode


and Cocoa Basics 3rd Edition Matt Neuburg

https://textbookfull.com/product/ios-10-programming-fundamentals-
with-swift-swift-xcode-and-cocoa-basics-3rd-edition-matt-neuburg/

iOS 11 Programming Fundamentals with Swift Swift Xcode


and Cocoa Basics 4th Edition Matt Neuburg

https://textbookfull.com/product/ios-11-programming-fundamentals-
with-swift-swift-xcode-and-cocoa-basics-4th-edition-matt-neuburg/
iOS 13 Programming Fundamentals with Swift Swift Xcode
and Cocoa Basics 1st Edition Matt Neuburg

https://textbookfull.com/product/ios-13-programming-fundamentals-
with-swift-swift-xcode-and-cocoa-basics-1st-edition-matt-neuburg/

iOS 14 Programming Fundamentals with Swift Covers iOS


14 Xcode 12 and Swift 5 3 7th Edition Matt Neuburg

https://textbookfull.com/product/ios-14-programming-fundamentals-
with-swift-covers-ios-14-xcode-12-and-swift-5-3-7th-edition-matt-
neuburg/

Programming iOS 14 11th Edition Matt Neuburg

https://textbookfull.com/product/programming-ios-14-11th-edition-
matt-neuburg/

Learn iOS 11 Programming with Swift 4 Craig Clayton

https://textbookfull.com/product/learn-ios-11-programming-with-
swift-4-craig-clayton/

Programming IOS 12 Dive Deep Into Views View


Controllers and Frameworks 1st Edition Matt Neuburg

https://textbookfull.com/product/programming-ios-12-dive-deep-
into-views-view-controllers-and-frameworks-1st-edition-matt-
neuburg/
Xc

C o 0,
od

ve a n
e1

rs d
i O Sw
S 1 if t
2, 4
.2
iOS 12
Programming
Fundamentals
with Swift
SWIFT, XCODE, AND COCOA BASICS

Matt Neuburg
FIFTH EDITION

iOS 12 Programming
Fundamentals with Swift
Swift, Xcode, and Cocoa Basics

Matt Neuburg

Boston
iOS 12 Programming Fundamentals with Swift, Fifth Edition
by Matt Neuburg
Copyright © 2018 Matt Neuburg. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://oreilly.com/safari). For more information, contact our corporate/insti‐
tutional sales department: 800-998-9938 or corporate@oreilly.com.

Editor: Rachel Roumeliotis Cover Designer: Karen Montgomery


Production Editor: Kristen Brown Interior Designer: David Futato
Proofreader: O’Reilly Production Services Illustrator: Matt Neuburg
Indexer: Matt Neuburg

April 2015: First Edition


October 2015: Second Edition
October 2016: Third Edition
October 2017: Fourth Edition
September 2018: Fifth Edition

Revision History for the Fifth Edition


2018-09-26: First release

See http://oreilly.com/catalog/errata.csp?isbn=9781492044550 for release details.

The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. iOS 12 Programming Fundamentals
with Swift, the image of a harp seal, and related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the author disclaim all responsibility
for errors or omissions, including without limitation responsibility for damages resulting from the use of
or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.

ISBN: 978-1-492-04455-0
[LSI]
Table of Contents

Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

Part I. Language
1. The Architecture of Swift. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Ground of Being 3
Everything Is an Object? 5
Three Flavors of Object Type 6
Variables 6
Functions 8
The Structure of a Swift File 9
Scope and Lifetime 11
Object Members 13
Namespaces 13
Modules 14
Instances 15
Why Instances? 17
The Keyword self 19
Privacy 20
Design 22
Object Types and APIs 23
Instance Creation, Scope, and Lifetime 25
Summary and Conclusion 25

2. Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Function Parameters and Return Value 27
Void Return Type and Parameters 31
Function Signature 32
External Parameter Names 32

iii
Overloading 34
Default Parameter Values 35
Variadic Parameters 35
Ignored Parameters 36
Modifiable Parameters 37
Function in Function 40
Recursion 42
Function As Value 42
Anonymous Functions 45
Define-and-Call 51
Closures 52
How Closures Improve Code 54
Function Returning Function 55
Closure Setting a Captured Variable 58
Closure Preserving Its Captured Environment 59
Escaping Closures 60
Curried Functions 60
Function References and Selectors 62
Function Reference Scope 64
Selectors 65

3. Variables and Simple Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69


Variable Scope and Lifetime 69
Variable Declaration 71
Computed Initializer 74
Computed Variables 76
Setter Observers 79
Lazy Initialization 80
Built-In Simple Types 82
Bool 82
Numbers 84
String 92
Character and String Index 96
Range 101
Tuple 103
Optional 105

4. Object Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119


Object Type Declarations and Features 119
Initializers 121
Properties 127
Methods 130

iv | Table of Contents
Subscripts 132
Nested Object Types 135
Instance References 135
Enums 137
Raw Values 138
Associated Values 140
Enum Case Iteration 142
Enum Initializers 143
Enum Properties 144
Enum Methods 145
Why Enums? 146
Structs 147
Struct Initializers, Properties, and Methods 147
Struct As Namespace 149
Classes 149
Value Types and Reference Types 150
Subclass and Superclass 156
Class Initializers 161
Class Deinitializer 169
Class Properties and Methods 170
Polymorphism 172
Casting 175
Casting Down 176
Type Testing and Casting Down Safely 176
Type Testing and Casting Optionals 178
Bridging to Objective-C 178
Type References 180
From Instance to Type 180
Type as Value 181
The Keyword Self 183
Comparing Types 184
Summary of Type Terminology 185
Protocols 186
Why Protocols? 187
Protocol Type Testing and Casting 189
Declaring a Protocol 190
Protocol Composition 191
Optional Protocol Members 192
Class Protocol 194
Implicitly Required Initializers 195
Literal Convertibles 196
Generics 197

Table of Contents | v
Generic Declarations 200
Contradictory Resolution 202
Type Constraints 203
Explicit Specialization 205
Generic Invariance 207
Associated Type Chains 208
Where Clauses 210
Extensions 213
Extending Object Types 213
Extending Protocols 215
Extending Generics 217
Umbrella Types 219
Any 219
AnyObject 221
AnyClass 223
Collection Types 224
Array 224
Dictionary 240
Set 247

5. Flow Control and More. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253


Flow Control 253
Branching 254
Loops 266
Jumping 271
Privacy 286
Private and Fileprivate 288
Public and Open 289
Privacy Rules 290
Introspection 290
Operators 291
Synthesized Protocol Implementations 295
Key Paths 298
Dynamic Member Lookup 300
Memory Management 301
Memory Management of Reference Types 301
Exclusive Access to Value Types 308

Part II. IDE

vi | Table of Contents
6. Anatomy of an Xcode Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
New Project 313
The Project Window 315
The Navigator Pane 317
The Utilities Pane 322
The Editor 323
The Project File and Its Dependents 325
What’s In the Project Folder 326
Groups 327
The Target 328
Build Phases 328
Build Settings 330
Configurations 331
Schemes and Destinations 333
From Project to Built App 335
Build Settings 338
Property List Settings 338
Nib Files 339
Additional Resources 340
Code Files 342
Frameworks and SDKs 343
The App Launch Process 345
The Entry Point 345
UIApplicationMain 346
App Without a Storyboard 348
Renaming Parts of a Project 349

7. Nib Management. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351


The Nib Editor Interface 352
Document Outline 353
Canvas 356
Inspectors and Libraries 358
Nib Loading 359
When Nibs Are Loaded 360
Manual Nib Loading 361
Connections 363
Outlets 363
The Nib Owner 364
Automatically Configured Nibs 368
Misconfigured Outlets 369
Deleting an Outlet 371
More Ways to Create Outlets 372

Table of Contents | vii


Outlet Collections 374
Action Connections 375
More Ways to Create Actions 377
Misconfigured Actions 379
Connections Between Nibs — Not! 379
Additional Configuration of Nib-Based Instances 380

8. Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
The Documentation Window 385
Class Documentation Pages 386
Quick Help 390
Symbol Declarations 392
Header Files 393
Sample Code 394
Internet Resources 394

9. Life Cycle of a Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397


Environmental Dependencies 397
Permissible Runtime Environment 398
Backward Compatibility 398
Device Type 400
Arguments and Environment Variables 401
Conditional Compilation 402
Version Control 404
Editing and Navigating Your Code 407
Autocompletion 409
Snippets 410
Fix-it and Live Syntax Checking 412
Navigation 413
Finding 415
Refactoring 416
Running in the Simulator 416
Debugging 417
Caveman Debugging 417
The Xcode Debugger 420
Testing 427
Unit Tests 428
Interface Tests 431
Clean 433
Running on a Device 433
Obtaining a Developer Program Membership 434
Signing an App 435

viii | Table of Contents


Automatic Signing 436
Manual Signing 439
Running the App 441
Managing Development Certificates and Devices 442
Profiling 442
Gauges 442
Memory Debugging 444
Instruments 445
Localization 448
Distribution 453
Making an Archive 453
The Distribution Certificate 454
The Distribution Profile 456
Distribution for Testing 457
Final App Preparations 458
Screenshots and Video Previews 461
Property List Settings 463
Submission to the App Store 464

Part III. Cocoa


10. Cocoa Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
Subclassing 469
Categories and Extensions 472
How Swift Uses Extensions 472
How You Use Extensions 473
How Cocoa Uses Categories 473
Protocols 475
Informal Protocols 477
Optional Methods 477
Some Foundation Classes 480
NSRange and NSNotFound 481
NSString and Friends 483
NSDate and Friends 486
NSNumber 487
NSValue 489
NSData 490
NSMeasurement and Friends 491
Equality, Hashability, and Comparison 491
NSArray and NSMutableArray 494
NSDictionary and NSMutableDictionary 496

Table of Contents | ix
NSSet and Friends 496
NSIndexSet 497
NSNull 498
Immutable and Mutable 498
Property Lists 500
Codable 501
Accessors, Properties, and Key–Value Coding 504
Swift Accessors 505
Key–Value Coding 507
Uses of Key–Value Coding 508
KVC and Outlets 510
Cocoa Key Paths 510
The Secret Life of NSObject 511

11. Cocoa Events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513


Reasons for Events 513
Subclassing 514
Notifications 516
Receiving a Notification 517
Unregistering 519
Posting a Notification 520
Timer 521
Delegation 523
Cocoa Delegation 523
Implementing Delegation 525
Data Sources 527
Actions 527
The Responder Chain 530
Deferring Responsibility 531
Nil-Targeted Actions 532
Key–Value Observing 533
Registration and Notification 534
Unregistering 535
Key–Value Observing Example 536
Swamped by Events 537
Delayed Performance 540

12. Memory Management. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543


Principles of Cocoa Memory Management 543
Rules of Cocoa Memory Management 544
What ARC Is and What It Does 545
How Cocoa Objects Manage Memory 546

x | Table of Contents
Autorelease Pool 547
Memory Management of Instance Properties 549
Retain Cycles and Weak References 550
Unusual Memory Management Situations 552
Notification Observers 552
KVO Observers 554
Timers 554
Other Unusual Situations 556
Nib Loading and Memory Management 556
Memory Management of CFTypeRefs 557
Property Memory Management Policies 559
Debugging Memory Management Mistakes 561

13. Communication Between Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563


Visibility by Instantiation 564
Visibility by Relationship 566
Global Visibility 567
Notifications and Key–Value Observing 569
Model–View–Controller 569

A. C, Objective-C, and Swift. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573

Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607

Table of Contents | xi
Preface

On June 2, 2014, Apple’s WWDC keynote address ended with a shocking announce‐
ment: “We have a new programming language.” This came as a huge surprise to the
developer community, which was accustomed to Objective-C, warts and all, and
doubted that Apple could ever possibly relieve them from the weight of its venerable
legacy. The developer community, it appeared, had been wrong.
Having picked themselves up off the floor, developers immediately began to consider
this new language — Swift — studying it, critiquing it, and deciding whether to use it.
My own first move was to translate all my existing iOS apps into Swift; this was
enough to convince me that Swift deserved to be, and probably would be, adopted by
new students of iOS programming, and that my books, therefore, should henceforth
assume that readers are using Swift.
That decision has proven prophetic. Programmers of iOS have flocked to Swift in
increasing numbers, and Swift itself has only improved. My iOS apps (such as Diabel‐
li’s Theme, LinkSame, Zotz!, TidBITS News, and my Latin and Greek flashcard apps)
have all been rewritten in Swift, and are far easier for me to understand and maintain
than their Objective-C originals.
Xcode 10 comes with Swift 4.2. The language has evolved greatly in its details and in
the nature of its integration with the Cocoa libraries that underlie iOS programming,
but its spirit has remained constant. The Swift language is designed from the ground
up with these salient features:
Object-orientation
Swift is a modern, object-oriented language. It is purely object-oriented: “Every‐
thing is an object.”
Clarity
Swift is easy to read and easy to write. Its syntax is clear, consistent, and explicit,
with few hidden shortcuts and minimal syntactic trickery.

xiii
Safety
Swift enforces strong typing to ensure that it knows, and that you know, what the
type of every object reference is at every moment.
Economy
Swift is a fairly small language, providing some basic types and functionalities
and no more. The rest must be provided by your code, or by libraries of code that
you use — such as Cocoa.
Memory management
Swift manages memory automatically. You will rarely have to concern yourself
with memory management.
Cocoa compatibility
The Cocoa APIs are written primarily in C and Objective-C. Swift is explicitly
designed to interface with most of the Cocoa APIs.
These features make Swift an excellent language for learning to program iOS.
The alternative, Objective-C, still exists, and you can use it if you like. Indeed, it is
easy to write an app that includes both Swift code and Objective-C code; and you may
have reason to do so. Objective-C, however, lacks the very advantages that Swift
offers. Objective-C agglomerates object-oriented features onto C. It is therefore only
partially object-oriented; it has both objects and scalar data types, and its objects have
to be slotted into one particular C data type (pointers). Its syntax can be difficult and
tricky; reading and writing nested method calls can make one’s eyes glaze over, and it
invites hacky habits such as implicit nil-testing. Its type checking can be and fre‐
quently is turned off, resulting in programmer errors where a message is sent to the
wrong type of object and the program crashes.
Recent revisions and additions to Objective-C — ARC, synthesis and autosynthesis,
improved literal array and dictionary syntax, blocks — have made it easier and more
convenient, but such patches have also made the language even larger and possibly
even more confusing. Because Objective-C must encompass C, there are limits to
how far it can be extended and revised. Swift, on the other hand, is a clean start. If
you were to dream of completely revising Objective-C to create a better Objective-C,
Swift might be what you would dream of. It puts a modern, rational front end
between you and the Cocoa Objective-C APIs.
Still, the reader may also need some awareness of Objective-C (including C). The
Foundation and Cocoa APIs, the built-in commands with which your code must
interact in order to make anything happen on an iOS device, are still written in C and
Objective-C. In order to interact with them, you might have to know what those lan‐
guages would expect.

xiv | Preface
Therefore, although I do not attempt to teach Objective-C in this book, I do describe
it in enough detail to allow you to read it when you encounter it in the documenta‐
tion and on the Internet, and I occasionally show some Objective-C code. Part III, on
Cocoa, is really all about learning to think the way Objective-C thinks — because the
structure and behavior of the Cocoa APIs are fundamentally based on Objective-C.
And the book ends with an appendix that details how Swift and Objective-C commu‐
nicate with one another, as well as explaining how your app can be written partly in
Swift and partly in Objective-C.

The Scope of This Book


This book is actually one of a pair with my Programming iOS 12, which picks up
exactly where this book leaves off. They complement and supplement one another.
The two-book architecture should, I believe, render the size and scope of each book
tractable for readers. Together, they provide a complete grounding in the knowledge
needed to begin writing iOS apps; thus, when you do start writing iOS apps, you’ll
have a solid and rigorous understanding of what you are doing and where you are
heading. If writing an iOS program is like building a house of bricks, this book
teaches you what a brick is and how to handle it, while Programming iOS 12 hands
you some actual bricks and tells you how to assemble them.
When you have read this book, you’ll know about Swift, Xcode, and the underpin‐
nings of the Cocoa framework, and you will be ready to proceed directly to Program‐
ming iOS 12. Conversely, Programming iOS 12 assumes a knowledge of this book; it
begins, like Homer’s Iliad, in the middle of the story, with the reader jumping with all
four feet into views and view controllers, and with a knowledge of the language and
the Xcode IDE already presupposed. If you started reading Programming iOS 12 and
wondered about such unexplained matters as Swift language basics, the
UIApplicationMain function, the nib-loading mechanism, Cocoa patterns of delega‐
tion and notification, and retain cycles, wonder no longer — I didn’t explain them
there because I do explain them here.
The three parts of this book teach the underlying basis of all iOS programming:
• Part I introduces the Swift language, from the ground up — I do not assume that
you know any other programming languages. My way of teaching Swift is differ‐
ent from other treatments, such as Apple’s; it is systematic and Euclidean, with
pedagogical building blocks piled on one another in what I regard as the most
helpful order. At the same time, I have tried to confine myself to the essentials.
Swift is not a big language, but it has some subtle and unusual corners. You don’t
need to dive deep into all of these, and my discussion will leave many of them
unexplored. You will probably never encounter them, and if you do, you will
have entered an advanced Swift world outside the scope of this discussion. To
give an obvious example, readers may be surprised to find that I never mention

Preface | xv
Swift playgrounds or the REPL. My focus here is real-life iOS programming, and
my explanation of Swift therefore concentrates on those common, practical
aspects of the language that, in my experience, actually come into play in the
course of programming iOS.
• Part II turns to Xcode, the world in which all iOS programming ultimately takes
place. It explains what an Xcode project is and how it is transformed into an app,
and how to work comfortably and nimbly with Xcode to consult the documenta‐
tion and to write, navigate, and debug code, as well as how to bring your app
through the subsequent stages of running on a device and submission to the App
Store. There is also a very important chapter on nibs and the nib editor (Interface
Builder), including outlets and actions as well as the mechanics of nib loading;
however, such specialized topics as autolayout constraints in the nib are post‐
poned to the other book.
• Part III introduces the Cocoa Touch framework. When you program for iOS, you
take advantage of a suite of frameworks provided by Apple. These frameworks,
taken together, constitute Cocoa; the brand of Cocoa that provides the API for
programming iOS is Cocoa Touch. Your code will ultimately be almost entirely
about communicating with Cocoa. The Cocoa Touch frameworks provide the
underlying functionality that any iOS app needs to have. But to use a framework,
you have to think the way the framework thinks, put your code where the frame‐
work expects it, and fulfill many obligations imposed on you by the framework.
To make things even more interesting, Cocoa uses Objective-C, while you’ll be
using Swift: you need to know how your Swift code will interface with Cocoa’s
features and behaviors. Cocoa provides important foundational classes and adds
linguistic and architectural devices such as categories, protocols, delegation, and
notifications, as well as the pervasive responsibilities of memory management.
Key–value coding and key–value observing are also discussed here.
The reader of this book will thus get a thorough grounding in the fundamental
knowledge and techniques that any good iOS programmer needs. The book itself
doesn’t show how to write any particularly interesting iOS apps, but it does constantly
use my own real apps and real programming situations to illustrate and motivate its
explanations. And then you’ll be ready for Programming iOS 12, of course!

Versions
This book is geared to Swift 4.2, iOS 12, and Xcode 10.
In general, only very minimal attention is given to earlier versions of iOS and Xcode.
It is not my intention to embrace in this book any detailed knowledge about earlier
versions of the software, which is, after all, readily and compendiously available in my
earlier books. The book does contain, nevertheless, a few words of advice about back‐
ward compatibility (especially in Chapter 9).

xvi | Preface
A word about method names. I generally give method names in Swift, in the style of a
function reference (as described in Chapter 2) — that is, the name plus parentheses
containing the parameter labels followed by colon. Now and then, if a method is
already under discussion and there is no ambiguity, I’ll use the bare name. In a few
places, such as Appendix A, where the Objective-C language is explicitly under dis‐
cussion, I use Objective-C method names.
Please bear in mind that Apple continues to make adjustments to the Swift language.
I have tried to keep my code up-to-date right up to the moment when the manuscript
left my hands; but if, at some future time, a new version of Xcode is released along
with a new version of Swift, some of the code in this book, and even some informa‐
tion about Swift itself, might be slightly incorrect. Please make allowances, and be
prepared to compensate.
Screenshots of Xcode were taken using Xcode 10 under macOS 10.13 High Sierra. I
have not upgraded my machine to macOS 10.14 Mojave, because at the time of this
writing it was too new to be trusted with mission-critical work. If you are braver than
I am and running Mojave, your interface may naturally look slightly different from
the screenshots (especially if you’re using “dark mode”), but this difference will be
minimal and shouldn’t cause any confusion.

Acknowledgments
My thanks go first and foremost to the people at O’Reilly Media who have made writ‐
ing a book so delightfully easy: Rachel Roumeliotis, Sarah Schneider, Kristen Brown,
Dan Fauxsmith, Adam Witwer, and Sanders Kleinfeld come particularly to mind.
And let’s not forget my first and long-standing editor, Brian Jepson, whose influence
is present throughout.
As in the past, I have been greatly aided by some fantastic software, whose excellences
I have appreciated at every moment of the process of writing this book. I should like
to mention, in particular:
• git (http://git-scm.com)
• Sourcetree (http://www.sourcetreeapp.com)
• TextMate (http://macromates.com)
• AsciiDoc (http://www.methods.co.nz/asciidoc)
• Asciidoctor (http://asciidoctor.org)
• BBEdit (http://barebones.com/products/bbedit/)
• EasyFind (http://www.devontechnologies.com/products/freeware.html)
• Snapz Pro X (http://www.ambrosiasw.com)
• GraphicConverter (http://www.lemkesoft.com)

Preface | xvii
• OmniGraffle (http://www.omnigroup.com)
The book was typed and edited entirely on my faithful Unicomp Model M keyboard
(http://pckeyboard.com), without which I could never have done so much writing over
so long a period so painlessly. For more about my physical work environment, see
http://matt.neuburg.usesthis.com.

From the Programming iOS 4 Preface


A programming framework has a kind of personality, an overall flavor that provides
an insight into the goals and mindset of those who created it. When I first encoun‐
tered Cocoa Touch, my assessment of its personality was: “Wow, the people who
wrote this are really clever!” On the one hand, the number of built-in interface
objects was severely and deliberately limited; on the other hand, the power and flexi‐
bility of some of those objects, especially such things as UITableView, was greatly
enhanced over their OS X counterparts. Even more important, Apple created a partic‐
ularly brilliant way (UIViewController) to help the programmer make entire blocks
of interface come and go and supplant one another in a controlled, hierarchical man‐
ner, thus allowing that tiny iPhone display to unfold virtually into multiple interface
worlds within a single app without the user becoming lost or confused.
The popularity of the iPhone, with its largely free or very inexpensive apps, and the
subsequent popularity of the iPad, have brought and will continue to bring into the
fold many new programmers who see programming for these devices as worthwhile
and doable, even though they may not have felt the same way about OS X. Apple’s
own annual WWDC developer conventions have reflected this trend, with their
emphasis shifted from OS X to iOS instruction.
The widespread eagerness to program iOS, however, though delightful on the one
hand, has also fostered a certain tendency to try to run without first learning to walk.
iOS gives the programmer mighty powers that can seem as limitless as imagination
itself, but it also has fundamentals. I often see questions online from programmers
who are evidently deep into the creation of some interesting app, but who are stymied
in a way that reveals quite clearly that they are unfamiliar with the basics of the very
world in which they are so happily cavorting.
It is this state of affairs that has motivated me to write this book, which is intended to
ground the reader in the fundamentals of iOS. I love Cocoa and have long wished to
write about it, but it is iOS and its popularity that has given me a proximate excuse to
do so. Here I have attempted to marshal and expound, in what I hope is a pedagogi‐
cally helpful and instructive yet ruthlessly Euclidean and logical order, the principles
and elements on which sound iOS programming rests. My hope, as with my previous
books, is that you will both read this book cover to cover (learning something new
often enough to keep you turning the pages) and keep it by you as a handy reference.

xviii | Preface
This book is not intended to disparage Apple’s own documentation and example
projects. They are wonderful resources and have become more wonderful as time
goes on. I have depended heavily on them in the preparation of this book. But I also
find that they don’t fulfill the same function as a reasoned, ordered presentation of
the facts. The online documentation must make assumptions as to how much you
already know; it can’t guarantee that you’ll approach it in a given order. And online
documentation is more suitable to reference than to instruction. A fully written
example, no matter how well commented, is difficult to follow; it demonstrates, but it
does not teach.
A book, on the other hand, has numbered chapters and sequential pages; I can
assume you know views before you know view controllers for the simple reason that
Part I precedes Part II. And along with facts, I also bring to the table a degree of expe‐
rience, which I try to communicate to you. Throughout this book you’ll find me
referring to “common beginner mistakes”; in most cases, these are mistakes that I
have made myself, in addition to seeing others make them. I try to tell you what the
pitfalls are because I assume that, in the course of things, you will otherwise fall into
them just as naturally as I did as I was learning. You’ll also see me construct many
examples piece by piece or extract and explain just one tiny portion of a larger app. It
is not a massive finished program that teaches programming, but an exposition of the
thought process that developed that program. It is this thought process, more than
anything else, that I hope you will gain from reading this book.

Conventions Used in This Book


The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program ele‐
ments such as variable or function names, databases, data types, environment
variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values deter‐
mined by context.

This element signifies a tip or suggestion.

Preface | xix
This element signifies a general note.

This element indicates a warning or caution.

Using Code Examples


Supplemental material (code examples, exercises, etc.) is available for download at
http://github.com/mattneub/Programming-iOS-Book-Examples.
This book is here to help you get your job done. In general, if example code is offered
with this book, you may use it in your programs and documentation. You do not
need to contact us for permission unless you’re reproducing a significant portion of
the code. For example, writing a program that uses several chunks of code from this
book does not require permission. Selling or distributing a CD-ROM of examples
from O’Reilly books does require permission. Answering a question by citing this
book and quoting example code does not require permission. Incorporating a signifi‐
cant amount of example code from this book into your product’s documentation does
require permission.
We appreciate, but do not require, attribution. An attribution usually includes the
title, author, publisher, and ISBN. For example: “iOS 12 Programming Fundamentals
with Swift by Matt Neuburg (O’Reilly). Copyright 2018 Matt Neuburg,
978-1-492-04455-0.”
If you feel your use of code examples falls outside fair use or the permission given
above, feel free to contact us at permissions@oreilly.com.

Safari® Books Online


Safari (formerly Safari Books Online) is a membership-
based training and reference platform for enterprise, gov‐
ernment, educators, and individuals.
Members have access to thousands of books, training videos, Learning Paths, interac‐
tive tutorials, and curated playlists from over 250 publishers, including O’Reilly
Media, Harvard Business Review, Prentice Hall Professional, Addison-Wesley Profes‐
sional, Microsoft Press, Sams, Que, Peachpit Press, Adobe, Focal Press, Cisco Press,
John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe
Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, and
Course Technology, among others.

xx | Preface
For more information, please visit http://oreilly.com/safari.

How to Contact Us
Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.


1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at http://bit.ly/ios12-prog-fundamentals.
To comment or ask technical questions about this book, send email to bookques‐
tions@oreilly.com.
For more information about our books, courses, conferences, and news, see our web‐
site at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia

Preface | xxi
PART I
Language

This part of the book teaches the Swift language, from the ground up. The descrip‐
tion is rigorous and orderly. Here you’ll become sufficiently conversant with Swift to
be comfortable with it, so that you can proceed to the practical business of actual
programming.
• Chapter 1 surveys the structure of a Swift program, both physically and concep‐
tually. You’ll learn how Swift code files are organized, and you’ll be introduced to
the most important underlying concepts of the object-oriented Swift language:
variables and functions, scopes and namespaces, object types and their instances.
• Chapter 2 explores Swift functions. We start with the basics of how functions are
declared and called; then we discuss parameters — external parameter names,
default parameters, and variadic parameters. Then we dive deep into the power
of Swift functions, with an explanation of functions inside functions, functions as
first-class values, anonymous functions, functions as closures, curried functions,
and function references and selectors.
• Chapter 3 starts with Swift variables — their scope and lifetime, and how they are
declared and initialized, along with features such as computed variables and set‐
ter observers. Then some important built-in Swift types are introduced, includ‐
ing Booleans, numbers, strings, ranges, tuples, and Optionals.
• Chapter 4 is all about Swift object types — classes, structs, and enums. It explains
how these three object types work, and how you declare, instantiate, and use
them. Then it proceeds to polymorphism and casting, protocols, generics, and
extensions. The chapter concludes with a discussion of Swift’s umbrella types,
such as Any and AnyObject, and collection types — Array, Dictionary, and Set
(including option sets).
• Chapter 5 is a miscellany. We start with Swift’s flow control structures for branch‐
ing, looping, and jumping, including error handling. Then I describe Swift access
control (privacy), introspection (reflection), and how to create your own opera‐
tors. There follows a discussion of some recently added Swift language features:
synthesized protocol implementations, key paths, and dynamic member lookup.
The chapter concludes by considering Swift memory management.
CHAPTER 1
The Architecture of Swift

It will be useful at the outset for you to have a general sense of how the Swift language
is constructed and what a Swift-based iOS program looks like. This chapter will sur‐
vey the overall architecture and nature of the Swift language. Subsequent chapters
will fill in the details.

Ground of Being
A complete Swift command is a statement. A Swift text file consists of multiple lines
of text. Line breaks are meaningful. The typical layout of a program is one statement,
one line:
print("hello")
print("world")

(The print command provides instant feedback in the Xcode console.)


You can combine more than one statement on a line, but then you need to put a
semicolon between them:
print("hello"); print("world")
You are free to put a semicolon at the end of a statement that is last or alone on its
line, but no one ever does (except out of habit, because C and Objective-C require the
semicolon):
print("hello");
print("world");
Conversely, a single statement can be broken into multiple lines, in order to prevent
long statements from becoming long lines. But you should try to do this at sensible
places so as not to confuse Swift. For example, after an opening parenthesis is a good
place:

3
print(
"world")
Comments are everything after two slashes in a line (so-called C++-style comments):
print("world") // this is a comment, so Swift ignores it

You can also enclose comments in /*...*/, as in C. Unlike C, C-style comments can
be nested.
Many constructs in Swift use curly braces as delimiters:
class Dog {
func bark() {
print("woof")
}
}
By convention, the contents of curly braces are preceded and followed by line breaks
and are indented for clarity, as shown in the preceding code. Xcode will help impose
this convention, but the truth is that Swift doesn’t care, and layouts like this are legal
(and are sometimes more convenient):
class Dog { func bark() { print("woof") }}
Swift is a compiled language. This means that your code must build — passing
through the compiler and being turned from text into some lower-level form that a
computer can understand — before it can run and actually do the things it says to do.
The Swift compiler is very strict; in the course of writing a program, you will often try
to build and run, only to discover that you can’t even build in the first place, because
the compiler will flag some error, which you will have to fix if you want the code to
run. Less often, the compiler will let you off with a warning; the code can run, but in
general you should take warnings seriously and fix whatever they are telling you
about. The strictness of the compiler is one of Swift’s greatest strengths, and provides
your code with a large measure of audited correctness even before it ever runs.
The Swift compiler’s error and warning messages, however, range from the insightful
to the obtuse to the downright misleading. You will often know that something is
wrong with a line of code, but the Swift compiler will not be telling you clearly exactly
what is wrong or even where in the line to focus your attention. My advice in these
situations is to pull the line apart into several lines of simpler code until you reach a
point where you can guess what the issue is. Try to love the compiler despite the occa‐
sional unhelpful nature of its messages. Remember, it knows more than you do, even
if it is sometimes rather inarticulate about its knowledge.

4 | Chapter 1: The Architecture of Swift


Everything Is an Object?
In Swift, “everything is an object.” That’s a boast common to various modern object-
oriented languages, but what does it mean? Well, that depends on what you mean by
“object” — and what you mean by “everything.”
Let’s start by stipulating that an object, roughly speaking, is something you can send a
message to. A message, roughly speaking, is an imperative instruction. For example,
you can give commands to a dog: “Bark!” “Sit!” In this analogy, those phrases are
messages, and the dog is the object to which you are sending those messages.
In Swift, the syntax of message-sending is dot-notation. We start with the object; then
there’s a dot (a period); then there’s the message. (Some messages are also followed by
parentheses, but ignore them for now; the full syntax of message-sending is one of
those details we’ll be filling in later.) This is valid Swift syntax:
fido.bark()
rover.sit()
The idea of everything being an object is a way of suggesting that even “primitive” lin‐
guistic entities can be sent messages. Take, for example, 1. It appears to be a literal
digit and no more. It will not surprise you, if you’ve ever used any programming lan‐
guage, that you can say things like this in Swift:
let sum = 1 + 2

But it is surprising to find that 1 can be followed by a dot and a message. This is legal
and meaningful in Swift (don’t worry about what it actually means):
let s = 1.description

But we can go further. Return to that innocent-looking 1 + 2 from our earlier code.
It turns out that this is actually a kind of syntactic trickery, a convenient way of
expressing and hiding what’s really going on. Just as 1 is actually an object, + is
actually a message; but it’s a message with special syntax (operator syntax). In Swift,
every noun is an object, and every verb is a message.
Perhaps the ultimate acid test for whether something is an object in Swift is whether
you can modify it. An object type can be extended in Swift, meaning that you can
define your own messages on that type. For example, you can’t normally send the say-
Hello message to a number. But you can change a number type so that you can:
extension Int {
func sayHello() {
print("Hello, I'm \(self)")
}
}
1.sayHello() // outputs: "Hello, I'm 1"

Everything Is an Object? | 5
Another Random Document on
Scribd Without Any Related Topics
sense the divine glory may be independent of created beings; but it
is not the primitiv sense of the word, nor the sense which answers
to the original meaning of the Greek doxe, and the Latin gloria.
No right in England and America is so much celebrated as that of
trial by peers; by which is commonly understood, trial by equals. The
right is valuable, but is not derived from the primitiv custom of trial
by equals; on the contrary, it is very questionable whether such a
custom existed prior to Alfred. Yet the trial by peers existed long
before, and can be traced back to the date of the Christian era. The
truth is, the word peer is not derived from the Latin par, equal; but
from the German, or Teutonic bar or par, which signified a
landholder, freeman or judge. The bars were that class of men who
held the fees or property in estates; and from whom the word baron
and the attendant privileges are derived. We have the same root in
baron, baronet, parliament, parish, and many other words, all
implying some degree of authority, eminence or jurisdiction. From
the same word bar or par, (for B and P are convertible letters) the
word peer is derived, as it is used in the common expressions house
of peers, trial by peers. It signified originally, not equals, but judges
or barons. The house of peers in England derives its appellation and
its jurisdiction from the ancient mode of trial by bars or barons; for it
is the final resort in all judicial cases. Yet the ancient English
lawyers, supposing the word to be from the Latin par, equal, have
explained it in that sense, and multiplied encomiums without end
upon the excellence of the privilege. The privilege is valuable, but its
excellence, if it consists in a trial by equals, is modern, compared
with the original custom, which was a trial by barons, or principal
landholders.
It is probable that our modern writers, misunderstanding the term
voluptas, have passed too severe censures upon epicures. The true
primitiv meaning of voluptas was that of pleasurable sensations
arising from innocent gratifications. Our modern word
voluptuousness carries with it a much stronger idea, and hence we
are led into an error reflecting the doctrine of Epicurus, who might
confine his ideas of pleasure to innocent gratifications.
We have been accustomed from childhood to hear the expressions,
the dew falls; the dews of heaven; and it is probable that nine
people out of ten, have never suspected the inaccuracy of the
phrases. But dew is merely the perspiration of the earth; it rises
instead of falling, and rises during the night.[63]
It was also supposed that manna in the eastern countries, came
from above, and it is called in scripture bread from heaven. Yet
manna is a gum, exuding from plants, trees and bushes, when
pierced by certain insects. The truth of this fact was not discovered,
till the middle of the sixteenth century.
Every man knows, when the prices of goods rise, it is said they
become dear; yet when the prices rise in consequence of an
overflowing sum of money in circulation, the fact is that the value of
money falls, and the value of goods remains the same. This
erroneous opinion had an amazing effect in raising popular clamor,
at the commencement of the late revolution.
I will name but one other instance, which has a material influence
upon our moral and religious opinions. It is said in scripture that God
hardened Pharaoh's heart. How? Was there a miracle in the case? By
no means. The manner of speaking leads us into the mistake. The
first cause is mentioned, and not the intermediate cause or causes.
So we should say, that General Washington attacked the British
troops at Monmouth; altho he was at a great distance when the
attack was commenced, and only ordered the attack. I suspect that
similar modes of speaking in scripture often lead superficial minds
into mistakes, and in some instances, giv occasion to infidels to scoff
at passages, which, if rightly understood, would silence all
objections.
This is a fruitful theme, and would lead an ingenious inquirer into a
wide field of investigation. But I have neither time nor talents to do
it justice; the few hints here suggested may have some effect in
convincing my readers of the importance and utility of all candid
researches into the origin and structure of speech; and pave the way
for further investigations, which may assist us in correcting our ideas
and ascertaining the force and beauty of our own language.
No. XIX.
PHILADELPHIA, 1787.

On VOCAL MUSIC.
The establishment of schools for teaching psalmody in this city is a
pleasing institution; but people seem not to understand the design,
or rather are not aware of the advantages which may result from it,
if properly conducted and encouraged. Most people consider music
merely as a source of pleasure; not attending to its influence on the
human mind, and its consequent effects on society. But it should be
regarded as an article of education, useful as well as ornamental.
The human mind is formed for activity; and will ever be employed in
business or diversions. Children are perpetually in motion, and all
the ingenuity of their parents and guardians should be exerted to
devise methods for restraining this activ principle, and directing it to
some useful object, or to harmless trifles. If this is not done, their
propensity to action, even without a vicious motiv, will hurry them
into follies and crimes. Every thing innocent, that attracts the
attention of children, and will employ their minds in leisure hours,
when idleness might otherwise open the way to vice, must be
considered as a valuable employment. Of this kind is vocal music.
There were instances of youth, the last winter, who voluntarily
attended a singing school in preference to the theatre. It is but
reasonable to suppose, that if they would neglect a theatre for
singing, they would neglect a thousand amusements, less engaging,
and more pernicious.
Instrumental music is generally prefered to vocal, and considered as
an elegant accomplishment. It is indeed a pleasing accomplishment;
but the preference given to it, is a species of the same false taste,
which places a son under the tuition of a drunken clown, to make
him a gentleman of strict morals.
Instrumental music may exceed vocal in some nice touches and
distinctions of sound; but when regarded as to its effects upon the
mind and upon society, it is as inferior to vocal, as sound is inferior
to sense. It is very easy for a spruce beau to display a contempt for
vocal music, and to say that human invention has gone beyond the
works of God Almighty. But till the system of creation shall be new
modelled, the human voice properly cultivated will be capable of
making the most perfect music. It is neglected; sol faing is
unfashionable, and that is enough to damn it: But people who have
not been acquainted with the perfection of psalmody, are incapable
of making a suitable comparison between vocal and instrumental
music. I have often heard the best vocal concerts in America, and
the best instrumental concerts; and can declare, that the music of
the latter is as inferior to that of the former, as the merit of a band
box macaroni is to that of a Cato.
Instrumental music affords an agreeable amusement; and as an
amusement it ought to be cultivated. But the advantage is private
and limited; it pleases the ear, but leaves no impression upon the
heart.
The design of music is to awaken the passions, to soften the heart
for the reception of sentiment. To awaken passion is within the
power of instruments, and this may afford a temporary pleasure; but
society derives no advantage from it, unless some useful sentiment
is left upon the heart.
Instruments are secondary in their use; they were invented
originally, not to supercede, but to assist the voice. The first histories
of all nations were written in verse, and sung by their bards. In later
ages, the oaten reed, the harp and the lyre, were found to improve
the pleasures of music; but the neglect of the voice and of sentiment
was reserved for modern corruption. Ignorant indeed is the man,
and possessed of a wretched taste, who can seriously despise the
humble pleasures of vocal music, and prefer the bare harmony of
sounds. Sentiment should ever accompany music; the sounds should
ever correspond with the ideas, otherwise music loses all its force.
Union of sentiment, with harmony of sounds, is the perfection of
music. Every string of the human heart may be touched; every
passion roused by the different kinds of sounds; the courage of the
warrior; the cruelty of the tyrant; anger; grief; love, with all its
sensibilities, are subject to the influence of music. Even brutes
acknowlege its effects; but while they in common with man feel the
effects of a harmony of mere sounds, man enjoys the superior
felicity of receiving sentiment; and while he relishes the pleasures of
chords in sound, he imbibes a disposition to communicate happiness
to society.
Seldom indeed do men reflect on the connexion between the chords
of music and the social affections. Morality is to immorality, what
harmony is to discord. Society detests vice, and the ear is offended
with discordant sounds. Society is pleased and happified with virtue,
and the ear is delighted with harmony. This beautiful analogy points
out the utility of cultivating music as a science. Harsh discordant
sounds excite the peevish malevolent passions; harmonious sounds
correct and soften the rougher passions.
Every person will acknowlege, that love refines the heart, and
renders it more susceptible, and more capable of social virtue. It is
for this reason that men who have particular attachments to women,
or associate much with ladies of delicacy, are more disposed to do
acts of kindness, in every sphere of life, than those who seldom
frequent ladies company. On the other hand, anger, jealousy, envy,
are dissocial passions; and even when they are excited by a single
object, they poison the heart, and disqualify it for exciting the social
affections towards any of the human race. Every institution,
therefore, calculated to prepare the human heart for exerting the
social virtues, and to suppress or check the malignant passions,
must be highly beneficial to society; and such I consider
establishments in favor of vocal music. Happy, indeed, should I feel,
could I see youth devoted every where to the refinement of their
voices and morals; to see them prefer moral or religious pieces to
the indecent songs or low diversions which taint the mind in early
life, and diffuse their pernicious influence through society.
If the poison of the tarantula may be counteracted by music; if the
Spanish ladies are won by nocturnal serenades; if the soldier is
inspired with courage by the martial sounds of the trumpet, and the
Christian impressed with devout sentiments by the solemn tones of
the organ; what advantage may society derive from the softening
harmony of choirs of voices, celebrating the praises of social virtue!
Happy days! when false taste and false opinions shall vanish before
the progress of truth; when princes shall resume their ancient and
honorable task of teaching the young to be good and great; when
an Addison shall be preferred to a Chesterfield; when the wealth of
nations shall be no longer lavished upon fiddlers and dancers; when
the characters of a Benezet and a Washington shall obscure the
glories of a Cæsar; and when no man shall be ashamed to be good,
because it is unfashionable.
No. XX.
NEW YORK, JUNE, 1788.

On MORALITY.
"The principles of morality are little understood among savages,"
says Lord Kaimes, "and if they arrive to maturity among enlightened
nations, it is by slow degrees."
With submission to that writer, I would advance another position
equally true, "that the principles of eating and drinking are little
understood by savages, and if they arrive to maturity among civilized
nations, it is by slow degrees."
The truth is, morality consists in discharging the social duties of life;
and so far as the state of savages requires an intercourse of duties,
the moral principles seem to be as perfect in them as in more
enlightened nations. Savages in a perfectly rude state have little or
no commerce; the transactions between man and man are confined
to very few objects, and consequently the laws which regulate their
intercourse and distribute justice, must be few and simple.[64] But
the crime of murder is as severely punished by savages, as by
civilized nations. Nay, I question whether it is possible to name the
barbarous tribe, which suffers an individual to take the life of
another, upon as easy terms as the modern feudal Barons in Europe
may do that of a vassal; or with the same impunity that a planter in
the West Indies takes the life of a slave. I speak of a time of peace,
and of the conduct of savages towards their own tribes. As to war,
every nation of savages has its arbitrary customs, and so has every
civilized nation. Savages are generally partial and capricious in the
treatment of their prisoners; some they treat with a singular
humanity; and others they put to death with the severest cruelty.
Well, do not civilized people the same? Did a savage ever endure
greater torments, than thousands of prisoners during the late war?
But not to mention the practice of a single nation, at a single period;
let us advert to a general rule among civilized nations; that it is
lawful to put to death prisoners taken in a garrison by storm. The
practice grounded on this rule, is as direct and as enormous a
violation of the laws of morality, as the slow deliberate tortures
exercised by the most barbarous savages on earth.
Well, what are the ideas of savages respecting theft? How do they
differ from those of an enlightened people? Many things are
possessed in common, as provisions taken in hunting, corn, &c.
Ferdinand de Soto relates, that the tribes (and he visited hundreds in
Florida) had public granaries of corn laid up for winter, which was
distributed by authority to each family, according to its number. But
for an individual to take from this common stock without license,
was considered as a criminal defrauding of the public. And with
regard to the few articles, in which individuals acquire private
property, the savages have as correct ideas of meum and tuum, of
theft, trespass, &c. and are as careful to guard private property from
invasion, by laws and penalties, as any civilized people. The laws of
the Creeks, the Cherokees, the Six Nations, &c. with regard to these
and many other crimes, in point of reason and equity, stand on a
footing with those of the most civilized nations; and in point of
execution and observance, their administration would do honor to
any government. Among most savage nations there is a kind of
monarchy which is efficient in administration; and among those
tribes which have had no intercourse with civilized nations, and
which have not been deceived by the tricks of traders; the common
arts of cheating, by which millions of enlightened people get a living
or a fortune, are wholly unknown. This is an incontrovertible fact. I
lately became acquainted with a lad of about twelve years old, who
was taken captiv by the Indians in 1778, while a child, and had
continued with them till about ten years old. He had no recollection
of the time when he was taken, and consequently his mind could not
have been corrupted among the English. When he was restored,
agreeable to the treaty, he was a perfect savage; but what I relate
the circumstance for, is this; the lad was not addicted to a single
vice. He was instant and cheerful in obeying commands; having not
even a disposition to refuse or evade a compliance. He had no
inclination to lie or steal; on the other hand, he was always surprised
to find a person saying one thing and meaning another. In short, he
knew not any thing but honesty and undisguised frankness and
integrity. A single instance does not indeed establish a general rule;
but those who are acquainted with the nativs of America can testify
that this is the general character of savages who are not corrupted
by the vices of civilized nations.
But it is said savages are revengeful; their hatred is hereditary and
perpetual. How does this differ from the hatred of civilized nations? I
question much whether the principle of revenge is not as perfect in
enlightened nations, as in savages. The difference is this; a savage
hunts the man who has offended him, like a wild beast, and
assassinates him wherever he finds him; the gentleman pursues his
enemy or his rival with as much rancor as a savage, and even stoops
to notice little affronts, that a savage would overlook; but he does
not stab him privately; he hazards his own life with that of his
enemy, and one or both are very honorably murdered. The principle
of revenge is equally activ in both cases; but its operation is
regulated by certain arbitrary customs. A savage is open and avows
his revenge, and kills privately; the polite and well bred take revenge
in a more honorable way, when life is to be the price of satisfaction;
but in cases of small affronts, they are content with privately
stabbing the reputation or ruining the fortunes of their enemies. In
short, the passions of a savage are under no restraint; the passions
of enlightened people are restrained and regulated by a thousand
civil laws and accidental circumstances of society.
But it will be objected, if savages understood principles of morality,
they would lay such passions under restraint. Not at all: Civil and
political regulations are not made, because the things prohibited are
in their own nature wrong; but because they produce
inconveniencies to society. The most enlightened nations do not
found their laws and penalties on an abstract regard to wrong; nor
has government any concern with that which has no influence on
the peace and safety of society. If savages, therefore, leave every
man to take his own revenge, it is a proof that they judge it the best
mode of preventing the necessity of it; that is, they think their
society and government safer under such a license, than under
regulations which should control the passions of individuals. They
may have their ideas of the nature of revenge independent of
society; but it will be extremely difficult to prove, that, abstracted
from a regard to a Deity and to society, there is such a thing as right
and wrong. I consider morality merely as it respects society; for if
we superadd the obligations of a divine command, we blend it with
religion; an article in which Christians have an infinit advantage over
savages.
Considering moral duties as founded solely on the constitution of
society, and as having for their sole end the happiness of social
beings, many of them will vary in their nature and extent, according
to the particular state and circumstances of any society.
Among the ancient Britons, a singular custom prevailed; which was,
a community of wives by common consent. Every man married one
woman; but a number, perhaps ten or twelve, relations or neighbors,
agreed to possess their wives in common. Every woman's children
were accounted the children of her husband; but every man had a
share in the common defence and care of this little community.[65]
Was this any breach of morality? Not in the least. A British woman,
in the time of Severus, having become intimate with Julia Augusta,
and other ladies, at the court of Rome, had observed what passed
behind the curtain; and being one day reproached for this custom of
the Britons, as infamous in the women, and barbarous in the men;
she replied, "We do that openly with the best of our men, which you
do privately with the worst of yours." This custom, so far from being
infamous or barbarous, originated in public and private convenience.
It prevented jealousy and the injuries of adultery, in a state where
private wrongs could not easily be prevented or redressed. It might
be an excellent substitute for penal laws and a regular
administration of justice. But there is a better reason for the custom,
which writers seem to have overlooked; and this is, that a
community multiplied the chances of subsistence and security. In a
savage life, subsistence is precarious, for it depends on contingent
supplies by hunting and fishing. If every individual, therefore, should
depend solely on his own good luck, and fail of success, his family
must starve. But in a community of twelve, the probability that some
one would procure provisions is increased as twelve to one. Hence
the community of provisions among most savage nations.[66]
The Britons, when the Romans first visited their island, did not
attend much to the cultivation of the earth. "Interiores plerique,"
says Cæsar, "frumenta non serunt, sed lacte et carne vivunt." By
establishing a community of goods, they secured themselves against
the hazard of want; and by a community of wives and offspring,
they confirmed the obligations of each to superintend the whole; or
rather, changed into a natural obligation what might otherwise
depend on the feebler force of positiv compact. Besides, it is very
possible that personal safety from the invasion of tribes or
individuals, might be another motiv for establishing these singular
communities. At any rate, we must suppose that the Britons had
good civil or political reasons for this custom; for even savages do
not act without reason. And if they found society more safe and
happy, with such a custom than without it, it was most undoubtedly
right.
Should it be said, that a community is prohibited by divine
command; I would answer that it is not presumable that the old
Britons had any positiv revelation; and I do not know that the law of
nature will decide against their practice. The commands given to the
Jews were positiv injunctions; but they by no means extend to all
nations, farther than as they are founded on immutable principles of
right and wrong in all societies. Many of the Mosaic precepts are of
this kind; they are unlimited in their extent, because they stand on
principles which are unlimited in their operation.
Adultery is forbidden in the Jewish laws; and so it is in the codes of
other nations. But adultery may be defined differently by different
nations; and the criminality of it depends on the particular positiv
institutions, or accidental circumstances of a nation. The same
reasons that would render a similar custom in civilized modern
nations highly criminal, might render it innocent and even necessary
among the old Britons. A prohibition to gather sticks on the Sabbath,
under a penalty of death for disobedience, might be founded on
good reasons among the ancient Jews; but it would be hard to prove
that a modern law of the same kind, would be warrantable in any
nation.
No. XXI.
NEW YORK, JUNE, 1788.

A LETTER from a LADY, with REMARKS.


s i r,

As you have, in your writings, discovered that you take a particular


interest in the happiness of ladies, I hope you will not deem it a
deviation from delicacy, if one of them offers you her grateful
acknowlegements, and requests you to giv your sentiments upon
what will be here related.
About four years ago, I was visited by a gentleman who professed
an unalterable attachment for me. He being a genteel, sensible and
handsome man, I thought myself justifiable in treating him with
complacency. After I was convinced by his constant attention and
frequent professions, that I was a favorite, he used frequently to
upbraid me, for being so silent and reserved: It shewed, he said, a
want of confidence in him; for I must be sensible he derived the
greatest pleasure imaginable in my conversation, and why would I
then deprive him of the greatest happiness by absenting myself,
when he paid a visit, refusing to chat with my usual freedom. Tho he
professed himself to be an admirer of candor, and a strict adherer to
the rules of honor, still I could not but doubt his sincerity from the
extravagance of his expressions. This he considered as an affront,
saying that no man of honor would express sentiments that were
not genuine. I found myself unwilling to say any thing that should be
disagreeable, and disposed to make him understand by an attention
that I supposed him entitled to, that he was prefered to any other
person. He continued his visits in this manner for about eighteen
months, conducting himself with the greatest delicacy, affection and
respect. During this time, he never expressed a wish to be united,
which made me uneasy, as I knew that all my friends thought us
engaged. At last I told him his attention was too particular; I knew
not what construction to put upon it. He replied that I was too
particular in my ideas; it was a convincing proof to him, with my
resenting trifling liberties, that I had not an affection for him, and
that he was not the man I wished to be connected with; therefore
he would not trouble me any longer with his company, and wished
me a good night.
This, Sir, you must suppose, distressed me greatly; I viewed myself
injured and trifled with, but knew not how to obtain redress. My
attachment and pride were so great that I would not allow my
friends to call him to an account for his behavior; tho I now despise
his conduct, and would refuse him the hand of which he has proved
himself unworthy, still I feel hurt at the treatment I have received.
You, Sir, as a friend to our sex, and one who wishes to preserve the
peace of mind of unsuspecting girls, will do them an essential
service, by your animadversions on these facts, and guarding our
sex from similar impositions.
These circumstances would not have been related, were I not
rendered discontented and wretched at home, in consequence of
refusing the offers of three other gentlemen; either of whom would
doubtless have been acceptable, had not my affections been
preengaged to one who has proved himself worthless. Their
characters and situations in life are equal to my wishes; but I cannot
do them so much injustice and myself so much injury, as to giv my
hand unaccompanied with my heart. In consulting my own
inclinations I have incurred the displeasure of all my family; they
treat me with great inattention, and are continually reflecting on my
want of spirit and resolution. I am confident, Sir, that every generous
mind will pity your unhappy and distressed friend,
CONSTANTIA.
To CONSTANTIA.
While I acknowlege myself honored by your correspondence, and
happy in an opportunity of rendering you or your sex the least
service, permit me, in compliance with your request, which shall be
to me a sacred law, to offer my sentiments with a frankness,
corresponding with that which marks the relation of your
misfortunes. For altho I feel the warmest indignation at every
species of deception, and particularly at that long continued
inexplicitness which is deliberate deception, and which is the cause
of your wretchedness, candor and truth require that censure should
fall where it is due.
If the slightest blame can fall on you, it is that you indulged the
visits of a gentleman for eighteen months without an explicit and
honorable declaration of his intention. A delicate, affectionate and
respectful attention to a lady, for one quarter of that period, is
sufficient to make an impression on her mind, and decide her
choice: At the same time, it might not render an attachment on her
part, so strong as to make a separation very painful; it might not giv
the world an opinion that an engagement exists, or subject the lady
to the necessity of dismissing other suitors. It is therefore prudent at
least for a lady to conduct herself in such a manner as to bring her
admirer to an explicit declaration of his designs. A man of real honor
and principle would not wait for a stratagem on the part of the lady,
or for a frank demand of an explanation of his conduct. A tolerable
acquaintance with the human heart would enable him to discover
when a declaration would be agreeable to the lady, and after this
discovery, he would not keep her a moment in suspense. A man of
generous feelings, who has a lively attachment, looks with anxiety
for some proof that his addresses are agreeable, and that a
declaration of his intentions will be well received. No sooner does he
find this proof, than he hastens to unbosom himself to the dear
object of his wishes, and communicate the happiness he so ardently
desires to receive. When therefore a man neglects such a
declaration, after he has had convincing proofs that his offers would
be well received, it may and should be taken for granted that his
intentions are not honorable, and the lady should treat him
accordingly. If therefore, my unhappy friend, you deserve the least
degree of censure, it is because you delayed too long to take
measures for undeceiving yourself. Yet this delay is a proof of your
unsuspecting confidence and sincere attachment; and faults,
proceeding from such amiable causes, are almost changed to
virtues; in your sex, they entitle the sufferer to forgivness and to
love.
You inform me, Constantia, that the man who has injured you,
professed to adhere to the rules of honor. Never, Constantia, trust a
man who deals largely in that hackneyed virtue, honor. Honor, in the
fashionable sense of the word, is but another name for villany. The
man of honor would not be guilty of the least impropriety in public
company; he would not for the world neglect the least punctilio of
the customary etiquette, but he would, without hesitation or
remorse, blow out the brains of a friend, for treading on his toe, or
rob an amiable woman of her reputation and happiness to gratify his
vanity.
If a man talks too much of his honor, he is to be avoided, like the
midnight ruffian. He that really possesses a virtue never boasts of it,
for he does not suspect the world think him destitute of it.
Numerous professions are commonly mere substitutes for what is
professed.
The man, who has given you so much uneasiness, never deserved
the confidence he won; he must be destitute of principle, of virtue,
and of attachment to you. His deliberate ill usage proves him to be
callous to every tender emotion, and to deserve your contempt. Will
not a generous pride and detestation expel the least sentiment of
respect for him from your breast? Can you not forget that you have
been misled, and will not your innocence buoy you above
misfortunes? That you have refused good offers, is to be regretted;
but your friends, if they know the reason, as they ought, will not
pain you by disingenuous reflections. On the other hand, they will
assist you in finding objects to amuse you and dissipate your own
melancholy reflections. Smile away the anxiety that shuts your heart
against other impressions. Base as men are, there may be some
found who despise the character of him who has given even an
hour's pain; there may be one who knows your worth, and may be
disposed to reward your constancy.
It is a mortifying reflection to an honest mind, that bad hearts are so
often suffered to giv pain to the good; that the trifling and the base
of our sex are not constrained, by necessity, to associate only with
the trifling and the base of yours, and that the good, the generous
and the constant should be exposed to the abuses of the fickle and
designing. But such is the constitution of society, and for the evils of
it, we have no remedy, but cautious circumspection to prevent, or
patient fortitude to support the adverse events of our conditions.
No man can entertain a more cordial detestation of the smallest
disposition to annoy the peace of mind and disturb the tranquillity of
mankind, than myself; the design of existence here is to sooth the
evils, and multiply the felicities of each other, and he must be a
villain indeed, who can deliberately attempt to poison the sources of
pleasure, by crossing and disappointing the social passions.
To your sex, Constantia, permit me to giv a word of caution; never
to make any inquiries about a man's family, fortune or
accomplishments, till you know whether he is a man of principle. By
principle, I mean, a disposition of heart to conduct with strict
propriety, both as a moral being and as a member of civil society;
that is, a disposition to increase the happiness of all around him. If
he appears to wish for his own gratification, at the expense even of
a servant's happiness, he is an unsocial being, he is not a fit
associate for men, much less for amiable women. If he is a man of
principle, then proceed to inquire into his standing in life. With
principle he may make a woman happy in almost any circumstances;
without it, birth, fortune and education serve but to render his
worthlessness the more conspicuous. With sentiments of esteem, I
am your obliged friend, and humble servant,
E.
No. XXII.
NEW YORK, JULY, 1788.

A LETTER to the AUTHOR, with REMARKS.


s i r,

I beg leave to relate to you a few circumstances respecting the


conduct of a young friend of mine in this city, and to request your
own remarks and advice on the occasion. Should any other person
similarly situated, be disposed to receive benefit from the advice, I
shall be much gratified, and my design more than answered.
This young friend to whom I allude, has been till within a few years,
under the watchful eyes of very attentiv parents; from whom he
received much better advice and much more of it, than the
generality of parents in this city are wont to bestow on their
children; they taught him to regard truth with a steady attachment;
in short his education, till their deaths, was such as might with
propriety have been called rigidly virtuous. Since that instructiv
period, he has been under the guidance of no one but himself; his
former associates with whom he grew up, and for whom he still feels
a degree of schoolmate attachment, are almost universally
debauched characters. The force of example is great, and let it be
mentioned to his honor, that in general he has had sufficient virtue
to resist their importunities, and to follow a line of conduct directly
contrary to the one they would gladly have marked out for his
pursuance. He possesses many of the social virtues, and is warmly
attached to the amiable part of the female world. This attachment
has preserved him from the fashionable vices of the age, and given
him a relish for domestic happiness, which I think he will never lose.
A young gentleman so capable of making himself agreeable to good
and virtuous characters, ought not, in my opinion, to indulge himself
in any practices, that shall tend in the least to depreciate his general
merit. The practices I would mention, are few and not very
considerable; still I think he should dismiss them entirely, or at least
not indulge them to his disadvantage. He sings a good song, and he
knows it tolerably well; he is often urged into company on that
account; he can make himself agreeable withal, and is really a
musical companion; he pays so much attention to learning and
singing songs, that he has but little leisure time on his hands; he
reads part of the day, but he reads principally novels or song books.
I would not be understood to consider singing songs as criminal; far
from it; I am often delighted with a song from him; but the query
with me is, whether he ought not to devote part of the time which
he now employs about what may be called genteel trifling, to the
improvement of his mind in a manner that may be of lasting benefit
to him; I wish you to giv him your advice, and direct him what books
to read. He has another fault, which, altho it originates in the
benevolence of his disposition, may still be called a fault. He has a
very susceptible heart, and opens it with a generous freedom, so
much so that he sometimes forgets himself, and opens it where he
ought not to do. A stranger with a specious outside might easily
impose on him. I just throw out these hints, that he may be on his
guard against those whose business it is to deceive. There are
several smaller faults dependant upon, or rather consequent to,
those I have mentioned, which I at first intended to have
enumerated, but if the first are amended, the others will forsake him
of course.
The ANSWER.
s i r,

By the description you have given of your young friend, it appears


that he is rather trifling and inconsiderate than profligate. His faults
are, his spending too much time in learning and singing songs; and
too much frankness of heart, which exposes him to impositions. But
you have not, Sir, informed me whether he was bred to business;
and by his character, I judge that he was not. He has had good
precepts indeed; but of how little weight are precepts to young
people! Advice to the young sometimes does good; but perhaps
never, except good habits have been previously formed by correct
discipline in manners, or by a mechanical attention to honest
employments. The truth is, advice or serious council is commonly
lavished where it does no good, upon the young, the gay, the
thoughtless; whose passions are strong, before reason begins to
have the smallest influence. I am young myself, but from the
observations I have hitherto made, I venture to affirm, that grave
advice never yet conquered a passion, and rarely has restrained one
so as to render a sprightly youth, in any degree serious. How should
it? Instructions are transient; they seldom touch the heart, and they
generally oppose passions that are vigorous, and which are
incessantly urging for indulgence.
I have ever thought that advice to the young, unaccompanied by the
routine of honest employments, is like an attempt to make a shrub
grow in a certain direction, by blowing it with a bellows. The way to
regulate the growth of a vegetable is to confine it to the proposed
direction. The only effectual method perhaps is to keep young
persons from childhood busy in some employment of use and
reputation. It is very immaterial what that employment is; the mind
will grow in the direction given it at first; it will bend and attach itself
to the business, and will not easily lose that bent or attachment
afterwards: The mind will attach itself to something; its natural
disposition is to pleasure and amusement. This disposition may be
changed or overcome by keeping the mind, from early life, busy in
some useful occupation, and perhaps by nothing else. Advice will not
produce the effect.
I suspect, Sir, that your young friend has been bred a trifler; that he
has had money to support him without the labor of acquiring it; that
he has never been anxious about his future subsistence. If so, his
education must be pronounced erroneous. Whether worth twenty
pounds or twenty thousand, it should make no difference in his
attention to business while young. We are the creatures of habit; a
habit of acquiring property should always precede the use of it,
otherwise it will not be used with credit and advantage. Besides,
business is almost the only security we have for moral rectitude and
for consequence in society. It keeps a young person out of vicious
company; it operates as a constant check upon the passions, and
while it does not destroy them, it restrains their intemperance; it
strengthens the mind by exercise, and puts a young person upon
exerting his reasoning faculties. In short, a man bred to business
loves society, and feels the importance of the principles that support
it. On the other hand, mankind respect him; and whatever your
young friend may think of the assertion, it is true that the ladies
uniformly despise a man who is always dangling at their apron
strings, and whose principal excellence consists in singing a good
song.
If, Sir, your friend is still so young, as to undergo the discipline of a
professional or other employment, his habits of trifling may be
changed by this means; but if he is so far the gentleman as to
disdain business, his friends have only to whistle advice in his ears,
and wait till old age, experience, and the death of his passions, shall
change the man.
Accept of my thanks, Sir, for this communication, and be assured
that my opinion on any subject of this kind will always be at your
service.
E.
No. XXIII.
BOSTON, MARCH, 1789.

An Enquiry into the Origin of the Words DOMESDAY,


PARISH, PARLIAMENT, PEER, BARON; with Remarks,
New and Interesting.
In the course of my etymological investigations, I hav been led to
suspect that all the writers on the laws and constitution of England,
hav mistaken the origin and primitiv signification of several words of
high antiquity, and in consequence of the mistake, hav adopted
some erroneous opinions, respecting the history of parliaments and
trial by peers. Whether my own opinions are wel supported by
history and etymology, must be hereafter decided by able and
impartial judges of this subject.
Dome book, or domesday book, iz a word wel understood by English
lawyers. Dome book, or dom bec, az it waz formerly spelt, waz the
name given to the Saxon code of laws compiled by Alfred. Some
other codes of local customs or laws were also denominated dom
becs, but theze are all lost. After the conquest, a general survey of
all the lands in England, except a few counties, waz made by order
of William, and recorded in a volum which iz stil extant, and called
domesday. This survey waz begun by five justices assigned for the
purpose in each county, in the year 1081 and completed 1086.
Our pious ancestors were not a little frightened at the name of this
book, which iz usually pronounced doomsday; supposing it to hav
some reference to the final doom, or day of judgement. In order to
quiet such apprehensions, lawyers of less credulity undertook to
refute the common opinion. Jacob, after Cowel, very gravely asserts,
that the termination day in this word does not allude to the general
judgement. "The addition of day to this dome book, waz not ment
with any allusion to the final day of judgement, az most persons hav
conceeved, but waz to strengthen and confirm it, and signifieth the
judicial decisiv record, or book of dooming judgement and justice."
[67] The same author defines domesmen to be judges, or men
appointed to doom.
Cowel, a compiler of considerable authority, says, "day or dey," (for
dey iz the true spelling) "does not augment the sense, but only
doubles and confirms the same meening. It does not, in this
composition, really signify the mesure of time, but the administration
of justice; so that domesday iz more emphatically the judicial decisiv
record, the book of dooming judgement."[68] According to this
author, then, domesday iz a judgement of judgements, for he quotes
Dr. Hammond to proov that day, dies, ημερα, in all idioms, signifies
judgement. However tru this may be, I beleev our Saxon forefathers
could find a better name for a code of laws, than a judgement of
judgements.
"Domesday," says Coke, "dies judicii," day of judgement.[69] Such is
the influence of sounds upon credulous, superstitious minds.
The truth seems to be this; domesday is a compound of dom,
judgement, decree or authority; and dey, a law or rule.[70] Or
domes, in the plural, may signify judges. The name of the book then
will signify, ether the rules of judging, or deciding, in questions
relating to the real property of England; or what is more probable,
the rules and determinations of the judges who surveyed the lands
in the kingdom.
That dom had the signification here explained iz capable of proof.
The homager's oath, in the black book of Hereford, fol. 46, ends
thus, "So helpe me God at his holy dome (judgement) and by my
trowthe," (troth, that is truth.)[71] This explanation coincides with
the meening of the same syllable in other languages, and confirms
the hypothesis of the common origin of the languages of Europe,
laid down in the Notes to my Dissertations on the English Tung. We
see the syllable in the Greek δαμαω, the Latin dominus, (domo) and
in the English word tame; az also in doom, deem, king dom.[72] In
all theze words we observe one primitiv and several derivativ
significations. Its primitiv sense is that of power or authority, az in
Greek and Latin. In English, it stands for jurisdiction, a judge, or a
sentence. In deem, it denotes the act of the mind in judging, or
forming its determinations.
The other syllable dey iz probably the same word az ley, law, with a
different prepositiv article; for etymologists tel us, that the radical
syllable waz often found in the muther tung ey. Cowel informs us it
waz not day, but dey; and another author writes it d'ey. The word
daysman, or az it ought to be spelt deysman, stil used both in
England and America, is composed of dey and man, and signifies an
arbitrator or judge, appointed to reconcile differences. In this
country I hav often heerd it applied to our Savior, az mediator
between God and man.
The ancient lawyers translate the Saxon dom bec and domesdey by
liber judicialis; words which seem not to convey the ful meening of
the original. I should translate them, liber judicum, the Judges book;
or lex judicum, the Judges law or rule.
The old Saxon word ley, before mentioned, waz, in different dialects,
or at different periods, written ley, lah, lage, laga. It iz doubtless
from the same root az the Latin lex, lege; and it is remarkable, that
the same word anciently signified peeple; and from this are derived
lay and laity, the peeple as opposed to the clergy.[73] It iz probable
that the primitiv sense of the word, in remote antiquity, waz people;
and az the peeple made the laws in general assembly, so their
orders or decrees came to be called by the same name. This
conjecture iz not groundless, and is no trifling proof of the ancient
freedom of our Gothic ancestors. Tacitus says expressly of the
Germans, "De minoribus rebus principes consultant; de majoribus
omnes." De Mor Germ. 11. The princes deliberate upon small
matters, or perhaps decide private controverses of small moment;
but laws of general concern are enacted in an assembly of all the
peeple.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like