SlideShare a Scribd company logo
Full download textbook at textbookfull.com
Learning Swift Building Apps for OSX, iOS,
and Beyond Jon Manning
https://textbookfull.com/product/learning-swift-
building-apps-for-osx-ios-and-beyond-jon-manning/
Download more textbook from https://textbookfull.com
More products digital (pdf, epub, mobi) instant
download maybe you interests ...
Learning Swift: Building Apps for macOS, iOS, and
Beyond 2nd Edition Paris Buttfield-Addison
https://textbookfull.com/product/learning-swift-building-apps-
for-macos-ios-and-beyond-2nd-edition-paris-buttfield-addison/
Biota Grow 2C gather 2C cook Loucas
https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-
loucas/
iOS 11 Swift Programming Cookbook Solutions and
Examples for iOS Apps 1st Edition Vandad Nahavandipoor
https://textbookfull.com/product/ios-11-swift-programming-
cookbook-solutions-and-examples-for-ios-apps-1st-edition-vandad-
nahavandipoor/
Swift 4 for Absolute Beginners: Develop Apps for iOS
4th Edition Stefan Kaczmarek
https://textbookfull.com/product/swift-4-for-absolute-beginners-
develop-apps-for-ios-4th-edition-stefan-kaczmarek/
Head First Swift 1st Edition Gray Anthony Manning Jon
Buttfield Addison Paris
https://textbookfull.com/product/head-first-swift-1st-edition-
gray-anthony-manning-jon-buttfield-addison-paris/
Developing Inclusive Mobile Apps: Building Accessible
Apps for iOS and Android 1st Edition Rob Whitaker
https://textbookfull.com/product/developing-inclusive-mobile-
apps-building-accessible-apps-for-ios-and-android-1st-edition-
rob-whitaker/
iOS 10 SDK Development Creating iPhone and iPad Apps
with Swift Chris Adamson
https://textbookfull.com/product/ios-10-sdk-development-creating-
iphone-and-ipad-apps-with-swift-chris-adamson/
iOS Unit Testing by Example XCTest Tips and Techniques
Using Swift 1st Edition Jon Reid
https://textbookfull.com/product/ios-unit-testing-by-example-
xctest-tips-and-techniques-using-swift-1st-edition-jon-reid/
Learn Swift by Building Applications Explore Swift
programming through iOS app development 1st Edition
Emil Atanasov
https://textbookfull.com/product/learn-swift-by-building-
applications-explore-swift-programming-through-ios-app-
development-1st-edition-emil-atanasov/
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning 2024 scribd download
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning 2024 scribd download
Jon Manning, Paris Buttfield-Addison, and Tim Nugent
Learning Swift 3
Boston Farnham Sebastopol Tokyo
Beijing Boston Farnham Sebastopol Tokyo
Beijing
978-1-491-96699-0
[FILL IN]
Learning Swift 3
by Paris Buttfield-Addison , Jon Manning , and Tim Nugent
Copyright © 2016 Secret Lab. 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://safaribooksonline.com ). For more information, contact our corporate/
institutional sales department: 800-998-9938 or corporate@oreilly.com .
Editor: Rachel Roumeliotis
Production Editor: FILL IN PRODUCTION EDI‐
TOR
Copyeditor: FILL IN COPYEDITOR
Proofreader: FILL IN PROOFREADER
Indexer: FILL IN INDEXER
Interior Designer: David Futato
Cover Designer: Karen Montgomery
Illustrator: Rebecca Demarest
January -4712: First Edition
Revision History for the First Edition
2016-12-05: First Early Release
See http://oreilly.com/catalog/errata.csp?isbn=9781491966990 for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning Swift 3, the cover image, and
related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the author(s) have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the author(s) disclaim all responsibil‐
ity 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.
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Part I. Swift Basics
1. Getting Started. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Apple Developer Program 5
Registering for the Apple Developer Program 6
Downloading Xcode 7
Creating Your First Project with Xcode 8
The Xcode Interface 12
Developing a Simple Swift Application 20
Designing the Interface 21
Connecting the Code 22
Using the iOS Simulator 24
Conclusion 26
2. The Basics of Swift. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
The Swift Programming Language 28
Swift 2 Versus Swift 3 30
Playgrounds 31
Comments 32
Variables and Constants 33
Operators 34
Control Flow 35
Loops 36
Switches 37
Types 40
iii
Working with Strings 40
Comparing Strings 41
Searching Strings 42
Optional Types 42
Type Casting 44
Tuples 45
Arrays 46
Dictionaries 48
Enumerations 48
Sets 50
Functions and Closures 51
Using Functions as Variables 54
Closures 56
The defer Keyword 58
The guard Keyword 58
Making your code Swifty 59
Conclusion 59
3. Swift for Object-Oriented App Development. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Classes and Objects 61
Initialization and Deinitialization 63
Properties 64
Inheritance 64
Protocols 68
Extensions 69
Access Control 70
Operator Overloading 72
Generics 73
Subscripts 74
Structures 75
Modules 76
The Swift Standard Library, Foundation, Cocoa, and Cocoa Touch 76
Swift Package Manager 77
Data 79
Loading Data from Files and URLs 79
Serialization and Deserialization 80
Error Handling 81
Memory Management 84
Design Patterns in Cocoa and Cocoa Touch 85
Model-View-Controller 85
Delegation 87
Structuring an App 89
iv | Table of Contents
The Application Delegate 89
Window Controllers and View Controllers 89
Nibs and Storyboards 90
Conclusion 90
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Part II. An OS X App
4. Setting Up the OS X Notes App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Designing the OS X Notes App 124
Creating the OS X Project 127
Defining a Document Type 132
Adding the Icon 136
Conclusion 138
5. Working with Documents on OS X. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
The NSDocument Class 139
Storing Data in the Document 140
Storing Text 141
Package File Formats 142
The guard Keyword, and Why It’s Great 147
Saving Files 148
Loading Files 151
A Basic UI 154
Conclusion 162
6. User Interfaces and iCloud. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Updating the UI 163
Document-Filetype-Extension UI 167
Getting an Icon for the Collection View Cells 172
Adding Attachments 174
Storing and Managing Attachments 182
Displaying Data in the Collection View 190
Enhancing Attachments 193
Opening Attachments 193
JSON Attachments 197
Adding Attachments via Drag-and-Drop 202
Adding QuickLook 207
iCloud 213
The Basics of iCloud 214
Table of Contents | v
Conclusion 217
Part III. An iOS App
7. Setting Up the iOS Notes App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Designing the iOS Notes App 222
Creating the iOS Project 228
Enabling the iOS App for iCloud 232
Defining a Document Type 236
Conclusion 238
8. Working with Files in iCloud. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
The App Sandbox 239
iCloud Availability 241
Creating the Document List View Controller 242
View Controllers and Storyboards 244
The Navigation Controller 244
Collection Views 248
Using Constraints to Control Size and Position 250
Creating the Document Class 254
Listing Documents 260
Creating Documents 270
Downloading from iCloud 272
Deleting Documents 276
Renaming Documents 283
Conclusion 286
9. Working with Documents on iOS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Adding a View to Display Notes 289
Editing and Saving Documents 297
Conclusion 299
10. Working with Files and File Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
Setting Up the Interface for Attachments 301
Listing Attachments 305
Determining Types of Attachments 307
Displaying Attachment Cells 310
Dealing with Conflicts 316
Creating the Quick Look Thumbnail 322
Conclusion 325
vi | Table of Contents
11. Images and Deletion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
Adding Attachments 327
Adding Image Attachments 329
Viewing Attachments 335
Deleting Attachments 346
Conclusion 353
12. Supporting the iOS Ecosystem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Sharing with UIActivityController 355
Handoffs 358
Searchability 363
Conclusion 365
13. Extending iOS Apps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Searching with a Spotlight Indexing Extension 368
Conclusion 378
14. Multimedia and Location attachments]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Audio Attachments 379
Video Attachments 392
Location Attachment 400
Conclusion 404
15. Polishing the iOS App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Opening Links in SFSafariViewController 405
3D Touch 409
Home Screen Quick Actions 410
Peek and Pop 413
Settings 414
Undo Support 416
Images with Filters 419
Worldwide Apps 423
Internationalization 424
Localization 427
Accessibility 432
Splitscreen Multitasking 437
Conclusion 438
Table of Contents | vii
Part IV. Extending Your Apps
16. Building a watchOS App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
Designing for the Watch 442
Designing Our watchOS App 444
Creating the watchOS Extension 446
Communicating with the iPhone 450
User Interfaces for the Apple Watch 469
Showing Note Contents 475
Creating New Notes 482
Adding Handoff Between the Watch and the iPhone 485
Glances 490
Conclusion 494
17. Code Quality and Distribution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
Debugging 495
Instruments 498
Testing 503
Unit Testing 504
UI Testing 506
Using Objective-C and Swift in the Same Project 508
Using Swift Objects in Objective-C 508
Using Objective-C Objects in Swift 509
The App Store 510
App Thinning 511
Testing iOS Apps with TestFlight 512
Conclusion 513
viii | Table of Contents
Preface
Welcome to Learning Swift 3! This book will help you put the Swift programming
language into practice by walking you through the development of a note-taking
application for the Apple iOS, OS X, and watchOS platforms.
Swift is a pretty amazing modern language, taking the best from other newer lan‐
guages without reinventing the wheel. Swift is easy to write, easy to read, and really
hard to make mistakes in.
Our philosophy is that the best way to learn Swift is to build apps using it! To build
apps, though, you need a great framework, and Apple has several: Cocoa, Cocoa
Touch, and WatchKit, to name only a few. This book could quite easily be titled
Learning Cocoa and Cocoa Touch with Swift, or something similar, because the frame‐
works are just as important as the language itself. At the time of writing, Swift is cur‐
rently at version 3, and has a bright future ahead of it.
Resources Used in This Book
We recommend following the book by writing code yourself as you progress through
each chapter. If you get stuck, or just want to archive a copy of the code, you can find
what you need via our website.
As this book teaches you how to build a real-world app, we primarily focus on show‐
ing you the coding side of things. We’re not going to ask you to paint your own icons,
so we’ve provided them for you. You can also download them from our website.
Audience and Approach
This book is solely focused on Swift 3 and does not cover the use of Objective-C. We
might mention it occasionally, but we don’t expect you to know how to use it. We first
cover the basics of the Swift 3 language, and then move on to teach as much of the
language as we can, as well as the use of the Cocoa, Cocoa Touch, and watchOS
ix
frameworks, through the construction of a complete app for both OS X and iOS. As a
reminder, Swift is the programming language, Cocoa is the framework for OS X apps,
Cocoa Touch is the framework for iOS apps, and somewhat predictably, watchOS is
the framework for the Apple Watch.
This book’s approach differs from that of other programming books that you may
have encountered. As we’ve mentioned, we believe that the best way to learn Swift is
to build apps using it. We assume that you’re a reasonably capable programmer, but
we don’t assume you’ve ever developed for iOS or OS X, or used Swift or Objective-C
before. We also assume that you’re fairly comfortable navigating OS X and iOS as a
user.
Organization of This Book
In this book, we’ll be talking about Cocoa and Cocoa Touch, the frameworks used on
OS X and iOS, respectively. Along the way, we’ll also be covering Swift, including its
syntax and features.
In Part I, Swift Basics, we begin with a look at the tools used for programming with
Swift, as well as the Apple Developer Program. Then we move on to the basics of the
Swift programming language and structuring a program for Apple’s platforms, as well
as common design patterns.
Chapter 1 covers the basics of Apple’s developer program, and guides you through a
simple Swift app.
Chapter 2 explores all the basics of Swift, and prepares you for using it to build more
complex applications.
Chapter 3 discusses Swift’s object-oriented features, as well as the structure of a good
app.
In Part II, An OS X App, we build a simple note-taking application for Macs, target‐
ing OS X. Along the way, we discuss the design of the app, how it’s structured, how it
uses documents, and how to build all the features.
Chapter 4 starts off our OS X notes app, and sets up the document model, and icon.
Chapter 5 goes into detail on working with documents in OS X apps.
Chapter 6 connects the app to iCloud, and finishes up the OS X app.
In Part III, An iOS App, we build a fully featured iOS note-taking application as a
companion for the OS X app from Part II.
Chapter 7 starts off our iOS app, and sets up the same document model for iOS.
Chapter 8 connects the iOS app to iCloud.
x | Preface
Chapter 9 creates an interface on iOS for displaying our notes.
Chapter 10 sets up the iOS app to handle attachments.
Chapter 11 adds image support to the iOS app.
Chapter 12 adds sharing and searching support to the iOS app.
Chapter 13 adds a today widget to the iOS app.
Chapter 14 adds location, audio, video, and contact attachments to the iOS app, as
well as notifications.
Chapter 15 finishes the iOS app with a whole lot of polish!
In Part IV, Extending Your Apps, we add a watchOS app, and explore bug hunting
and performance tuning.
Chapter 16 adds a watchOS app to the iOS app, allowing for Apple Watch support.
Chapter 17 explores debugging and performance tuning.
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 | xi
This element signifies a general note.
This element indicates a warning or caution.
Using Code Examples
Supplemental material (code examples, exercises, errata, etc.) is available for down‐
load at our website.
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: “Learning Swift by Jonathon Man‐
ning, Paris Buttfield-Addison, and Tim Nugent (O’Reilly). Copyright 2016 Secret Lab,
978-1-491-94074-7.”
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 Books Online is an on-demand digital library that deliv‐
ers expert content in both book and video form from the
world’s leading authors in technology and business.
Technology professionals, software developers, web designers, and business and crea‐
tive professionals use Safari Books Online as their primary resource for research,
problem solving, learning, and certification training.
xii | Preface
Safari Books Online offers a range of plans and pricing for enterprise, government,
education, and individuals.
Members have access to thousands of books, training videos, and prepublication
manuscripts in one fully searchable database from publishers like O’Reilly Media,
Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que,
Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kauf‐
mann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders,
McGraw-Hill, Jones & Bartlett, Course Technology, and hundreds more. For more
information about Safari Books Online, please visit us online.
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/learning-swift.
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
Acknowledgments
Jon thanks his mother, father, and the rest of his crazily extended family for their tre‐
mendous support.
Paris thanks his mother, without whom he wouldn’t be doing anything nearly as
interesting, let alone writing books.
Tim thanks his parents and family for putting up with his rather lackluster approach
to life.
Preface | xiii
We’d all like to thank our editors, Rachel Roumeliotis and Brian MacDonald—their
skill and advice were invaluable to completing the book. Likewise, all the O’Reilly
Media staff we’ve interacted with over the course of writing the book have been the
absolute gurus of their fields.
A huge thank you to Tony Gray and the Apple University Consortium (AUC) for the
monumental boost they gave us and others listed on this page. We wouldn’t be writ‐
ing this book if it weren’t for them. And now you’re writing books, too, Tony—sorry
about that!
Thanks also to Neal Goldstein, who deserves full credit and/or blame for getting us
into the whole book-writing racket.
We’re thankful for the support of the goons at MacLab (who know who they are and
continue to stand watch for Admiral Dolphin’s inevitable apotheosis), as well as pro‐
fessor Christopher Lueg, Dr. Leonie Ellis, and the rest of the staff at the University of
Tasmania for putting up with us. “Apologies” to Mark Pesce. He knows why.
Additional thanks to Rex S., Nic W., Andrew B., Jess L., and Ash J., for a wide variety
of reasons. And very special thanks to Steve Jobs, without whom this book (and many
others like it) would not have reason to exist.
Thanks also to our tech reviewers, with special thanks to Chris Devers and Tony Gray
for their thoroughness and professionalism.
Finally, thank you very much for buying our book—we appreciate it! And if you have
any feedback, please let us know. You can email us at lab@secretlab.com.au and find us
on Twitter @thesecretlab.
xiv | Preface
PART I
Swift Basics
Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning 2024 scribd download
CHAPTER 1
Getting Started
This book is a work-in-progress. We will be releasing regular Early
Release editions, with a final version late in 2016. The book may be
inconsistent, out of date, or incomplete until then. Please let us
know if you have any feedback by emailing learningswift@secret‐
lab.com.au
This book teaches the Swift 3 programming language by exploring the development
of three applications for Apple platforms: OS X, iOS, and watchOS. This book’s
approach might differ from what you’re used to, because our philosophy is that the
best way to learn Swift is to build apps using it! The vast majority of the code in this
book will be part of the apps we’re building—a full note-taking app for OS X, iOS,
and watchOS—rather than individual pieces of sample code. You can see the final
product in Figure 1-1.
3
Figure 1-1. Our finished app, for OS X, iOS, and watchOS
Our app is fully functional, but we do make some deliberate design and feature deci‐
sions along the way to constrain the scope a little (the book is more than 500 pages!).
As we mentioned in the preface, we assume that you’re a reasonably capable pro‐
grammer, but we don’t assume you’ve ever developed for iOS or OS X, or used Swift
or Objective-C before. We also assume that you’re fairly comfortable navigating OS X
and iOS as a user.
We recommend that you work through this book front to back,
building the OS X app, then the iOS app, then the watchOS app,
even if you’re only interested in one of the platforms. By approach‐
ing the book this way, you’ll get the best understanding of what
building a real app with Swift requires.
Programming with Swift, and using the Cocoa and Cocoa Touch frameworks to
develop OS X and iOS apps, respectively, involves using a set of tools developed by
Apple. In this chapter, you’ll learn about these tools, where to get them, how to use
them, how they work together, and what they can do. At the end of this chapter, you’ll
make a very simple Swift application for iOS, before we dive into the details of the
Swift language and Apple’s frameworks in the following two chapters.
4 | Chapter 1: Getting Started
The Apple development tools have a long and storied history. Orig‐
inally a set of standalone application tools for the NeXTSTEP OS,
they were eventually adopted by Apple for use as the official OS X
tools. Later, Apple largely consolidated them into one application,
known as Xcode, though some of the applications (such as Instru‐
ments and the iOS simulator) remain somewhat separate, owing to
their relatively peripheral role in the development process. You’ll
notice the prefix NS on many of the classes you use for Cocoa and
Cocoa Touch development with Swift. This prefix comes from the
NeXTSTEP heritage of many of Apple’s frameworks.
In addition to the development tools, Apple offers developers a paid membership in
its Developer Program, which provides resources and support. The program allows
access to online developer forums and specialized technical support for those interes‐
ted in talking to the framework engineers. If you are just interested in learning Swift
and exploring the development tools, you can do so for free. You will need a paid
membership, however, if you wish to use developer services like iCloud in your apps,
or to distribute anything you build through either the iOS or OS X App Store.
Swift is open source, but this doesn’t really mean much when it
comes to using it to develop apps for OS X, iOS, and watchOS.
There’s an excellent community of people working on the language
that you can find at the Swift website.
With the introduction of Apple’s curated App Stores for OS X, iOS, and watchOS, as
well as emerging Apple platforms like tvOS, the Developer Program has become the
official way for developers to provide their credentials when submitting applications
to Apple—in essence, it is your ticket to selling apps through Apple. In this chapter,
you’ll learn how to sign up for the Apple Developer Program, as well as how to use
Xcode, the development tool used to build apps in Swift.
The Apple Developer Program
The paid Apple Developer Program provides access to beta development tools, beta
operating system releases, and distribution ability through Apple’s App Stores. It also
allows you to use some of the cloud-dependent features of the platforms, such as
iCloud, CloudKit, In-App Purchase, Maps, and App Groups.
We will be using a lot of cloud-dependent features, including Maps
and iCloud, in the apps we build throughout this book. You will
not be able to run these apps if you do not have a paid member‐
ship.
The Apple Developer Program | 5
It isn’t necessary to be a member of the Apple Developer Program if you don’t intend
to submit apps to the App Stores, or don’t need the cloud-dependent features. We
strongly recommend joining, though, if you intend to build apps for any of Apple’s
platforms, as the other benefits are substantial:
• Access to the Apple Developer Forums, which are frequented by Apple engineers
and designed to allow you to ask questions of your fellow developers and the
people who wrote the OS.
• Access to beta versions of the OS before they are released to the public, which
enables you to test your applications on the next version of the OS X, iOS,
watchOS, and tvOS platforms, and make necessary changes ahead of time. You
also receive beta versions of the development tools.
• A digital signing certificate (one for each platform) used to identify you to the
App Stores. Without this, you cannot submit apps to the App Store, making a
membership mandatory for anyone who wants to release software either for free
or for sale via an App Store.
That said, registering for the Developer Program isn’t necessary to view the docu‐
mentation or to download the current version of the developer tools, so you can play
around with writing apps without opening your wallet.
Registering for the Apple Developer Program
To register for the Developer Program, you’ll first need an Apple ID. It’s quite likely
that you already have one, as the majority of Apple’s online services require one to
identify you. If you’ve ever used iCloud, the iTunes store (for music or apps), or
Apple’s support and repair service, you already have an ID. You might even have
more than one (one of this book’s authors has four). If you don’t yet have an ID, you’ll
create one as part of the registration process. When you register for the Developer
Program, the membership gets added to your Apple ID.
If you don’t want to register for the paid developer program, you
can skip to “Downloading Xcode” on page 7 for instructions on
installing Xcode, the developer tools.
Once again, keep in mind that you won’t be able to build the apps
that we teach in this book if you don’t have a paid membership, as
we use cloud-dependent features such as iCloud and Maps.
There are alternatives to many of Apple’s tools—such as the Google
Maps SDK for iOS, or cloud-storage services from Amazon and
Microsoft. However, you’ll still need a paid membership through
Apple to put apps in the iTunes App Store.
6 | Chapter 1: Getting Started
Once you’re on the Apple Developer Program website, simply click Enroll, and follow
the steps to enroll.
You can choose to register as an individual or as a company. If you register as an indi‐
vidual, your apps will be sold under your name. If you register as a company, your
apps will be sold under your company’s legal name. Choose carefully, as it’s very diffi‐
cult to convince Apple to change your program’s type.
If you’re registering as an individual, you’ll just need your credit card. If you’re regis‐
tering as a company, you’ll need your credit card as well as documentation that
proves you have authority to bind your company to Apple’s terms and conditions.
For information on code signing and using Xcode to test and run
your apps on your own physical devices, see Apple’s App Distribu‐
tion Guide. We don’t cover this in the book, as it’s a process that
changes often.
Apple usually takes about 24 hours to activate an account for individuals, and longer
for companies. Once you’ve received confirmation from Apple, you’ll be emailed a
link to activate your account; when that’s done, you’re a full-fledged developer!
Downloading Xcode
To develop apps for either platform, you’ll use Xcode, Apple’s integrated development
environment. Xcode combines a source code editor, debugger, compiler, profiler, iOS
simulator, Apple Watch simulator, and more into one package. It’s where you’ll spend
the majority of your time when developing applications.
At the time of writing, Xcode is only available for Mac, but who
knows what the future holds for the iPad Pro?
You can get Xcode from the Mac App Store. Simply open the App Store application
and search for “Xcode,” and it’ll pop up. It’s a free download, though it’s rather large
(several gigabytes at the time of writing).
Once you’ve downloaded Xcode, it’s straightforward enough to install it. The Mac
App Store gives you an application that on first launch sets up everything you need to
use Xcode. Just launch the downloaded app, and follow the prompts, and you’ll be up
and running in no time.
The Apple Developer Program | 7
This book covers Swift 3, which is available only if you’re using
Xcode 7 or later. Make sure you’re using the latest version of Xcode
from the Mac App Store. It’s good practice to use the latest Xcode at
all times.
Creating Your First Project with Xcode
Xcode is designed around a single window. Each of your projects will have one win‐
dow, which adapts to show what you’re working on.
To start exploring Xcode, you’ll first need to create a project by following these steps:
1. Launch Xcode. You can find it by opening Spotlight (by pressing ⌘-space bar)
and typing Xcode. You can also find it by opening the Finder, going to your hard
drive, and opening the Applications directory. If you had any projects open previ‐
ously, Xcode will open them for you. Otherwise, the Welcome to Xcode screen
appears (see Figure 1-2).
Figure 1-2. The Welcome to Xcode screen
2. Create a new project by clicking “Create a new Xcode project” or go to
File→New→Project.
You’ll be asked what kind of application to create. The template selector is divi‐
ded into two areas. On the lefthand side, you’ll find a collection of application
categories. You can choose to create an iOS, watchOS, or OS X application from
the project templates, which will set up a project directory to get you started.
8 | Chapter 1: Getting Started
Because we’re just poking around Xcode at the moment, it doesn’t really matter
what we select, so choose Application under the iOS header and select Single
View Application. This creates an empty iOS application and displays the project
settings window shown in Figure 1-3.
Figure 1-3. The project settings window
3. Name the application. Enter HelloSwift in the Product Name section.
4. Enter information about the project. Depending on the kind of project template
you select, you’ll be asked to provide different information about how the new
project should be configured.
At a minimum, you’ll be asked for the following information, no matter which
platform and template you choose:
The product’s name
This is the name of the project and is visible to the user. You can change this
later.
Your organization’s name
This is the name of your company or group. It’s not directly used by Xcode,
but new source code files that you create will mention it.
Creating Your First Project with Xcode | 9
Your organization identifier
This is used to generate a bundle ID, a string that looks like a reverse domain
name (e.g., if O’Reilly made an application named MyUsefulApplication, the
bundle ID would be com.oreilly.MyUsefulApplication).
Bundle IDs are the unique identifier for an application,
and are used to identify that app to the system and to the
App Store. Because each bundle ID must be unique, the
same ID can’t be used for more than one application in
either of the iOS or Mac App Stores. That’s why the for‐
mat is based on domain names—if you own the site use‐
fulsoftware.com, all of your bundle IDs would begin with
com.usefulsoftware, and you won’t accidentally use a bun‐
dle ID that someone else is using or wants to use because
nobody else owns the same domain name.
If you don’t have a domain name, enter anything you like, as long as it looks
like a backward domain name (e.g., com.mycompany will work).
If you plan on releasing your app, either to the App Store
or elsewhere, it’s very important to use a company identi‐
fier that matches a domain name you own. The App Store
requires it, and the fact that the operating system uses the
bundle ID that it generates from the company identifier
means that using a domain name that you own eliminates
the possibility of accidentally creating a bundle ID that
conflicts with someone else’s.
If you’re writing an application for the Mac App Store, you’ll also be prompted
for the App Store category (whether it’s a game, an educational app, a social net‐
working app, or something else).
Depending on the template, you may also be asked for other information (e.g.,
the file extension for your documents if you are creating a document-aware
application, such as a Mac app). You’ll also be asked which language you want to
use; because this book is about Swift, you should probably choose Swift! The
additional information needed for this project is covered in the following steps.
5. Make the application run on the iPhone by choosing iPhone from the Devices
drop-down list.
10 | Chapter 1: Getting Started
iOS applications can run on the iPad, iPhone, or both. Appli‐
cations that run on both are called “universal” applications and
run the same binary but have different user interfaces. For this
exercise, just choose iPhone. You should be building universal
iOS apps, in general, and we’ll be doing that when we properly
start on iOS, in Part III.
6. Leave the rest of the settings as shown in Figure 1-4. Click Next to create the
project.
Figure 1-4. The project settings
7. Choose where to save the project. Select a location that suits you. We recommend
putting all your work related to this book (and other Swift programming learning
you might do) in one folder. You might notice a little checkbox for Source Con‐
trol; this creates a source code control repository for your code, giving you a
place where you can save and manage different versions of your code as you cre‐
ate them. While in general this is a good idea to use, for this example project,
make sure this is unchecked.
Once you’ve done this, Xcode will open the project, and you can now start using the
entire Xcode interface, as shown in Figure 1-5.
Creating Your First Project with Xcode | 11
Figure 1-5. The entire Xcode interface
The Xcode Interface
As mentioned, Xcode shows your entire project in a single window, which is divided
into a number of sections. You can open and close each section at will, depending on
what you want to see.
Let’s take a look at each of these sections and examine what they do.
The editor
The Xcode editor (Figure 1-6) is where you’ll be spending most of your time. All
source code editing, interface design, and project configuration take place in this sec‐
tion of the application, which changes depending on which file you have open.
If you’re editing source code, the editor is a text editor, with code completion, syntax
highlighting, and all the usual features that developers have come to expect from an
integrated development environment. If you’re modifying a user interface, the editor
becomes a visual editor, allowing you to drag around the components of your inter‐
face. Other kinds of files have their own specialized editors as well.
When you first create a project, the editor will start by showing the project settings, as
seen in Figure 1-6.
12 | Chapter 1: Getting Started
Figure 1-6. Xcode’s editor, showing the project settings
The editor can also be split into a main editor and an assistant editor through the edi‐
tor selector. The assistant shows files that are related to the file open in the main edi‐
tor. It will continue to show files that have a relationship to whatever is open, even if
you open different files.
For example, if you open an interface file and then open the assistant, the assistant
will, by default, show related code for the interface you’re editing. If you open another
interface file, the assistant will show the code for the newly opened files.
At the top of the editor, you’ll find the jump bar. The jump bar lets you quickly jump
from the content that you’re editing to another piece of related content, such as a file
in the same folder. The jump bar is a fast way to navigate your project.
The toolbar
The Xcode toolbar (Figure 1-7) acts as mission control for the entire interface. It’s the
only part of Xcode that doesn’t significantly change as you develop your applications,
and it serves as the place where you can control what your code is doing.
Figure 1-7. Xcode’s toolbar
From left to right, after the OS X window controls, the toolbar features the following
items:
Run button (Figure 1-8)
Clicking this button instructs Xcode to compile and run the application.
Creating Your First Project with Xcode | 13
Another random document with
no related content on Scribd:
‘Choked is my stream with dead men!’ it cried, ‘and still thou
slayest!’
But when Achilles heeded not, in fierce flood the river uprose
against him, sweeping the slain before it, and in furious spate
seeking to destroy Achilles. But as its waves smote against his
shield, Achilles grasped a tall elm, and uprooting it, cast it into the
river to dam the torrent. For the moment only was the angry river
stayed. In fear did Achilles flee across the plain, but with a mighty
roar it pursued him, and caught him.
To the gods then cried Achilles, and to his aid came Athene, and
close to the walls of Troy again did Achilles chase the Trojan men.
From the city walls old Priam saw the dreadful things Achilles
wrought.
And when, his armour blazing like the brightest stars of the sky,
he drew near, and Hector would have gone to meet him, in grief did
Priam cry to his dearly-loved son:
‘Hector, beloved son, I pray thee go not alone to meet this man;
mightier far than thou is he.’
But all eager for the fight was Hector. Of all the men of Troy he
alone still stood unafraid. Then did the mother of Hector beseech
him to hold back from what must surely mean death. Yet Hector held
not back, but on his shining shield leaned against a tower, awaiting
the coming of the great destroyer.
And at last they met, face to face, spear to spear. As a shooting-
star in the darkness so flashed the spear of Achilles as he hurled it
home to pierce the neck of Hector. Gods and men had deserted
Hector, and alone before the walls of Troy he fell and died.
Thus ended the fight.
For twelve days did the Greek host rejoice, and all through the
days Hector’s body lay unburied. For at the heels of swift horses had
the Greeks dragged him to the ships, while from the battlements his
mother and his wife Andromache watched, wailing in agony, with
hearts that broke.
The shadow of death came down upon Hector (page 116)
Then at length went old Priam to the camp of the Greeks. And
before Achilles he fell, beseeching him to have mercy and to give
him back the body of his son.
So was the heart of Achilles moved, and the body of Hector
ransomed; and with wailing of women did the people of Troy
welcome home their hero.
Over him lamented his old mother, for of all her sons was he to
her most dear, and over him wept, with burning tears, his wife
Andromache.
And to his bier came Helen, and with breaking heart did she sob
forth her sorrow.
‘Dearest of my brothers,’ she said, ‘from thee have I heard
neither reproach nor evil word. With kind words and gentle heart hast
thou ever stood by me. Lost, lost is my one true friend. No more in
Troyland is any left to pity me.’
On lofty funeral pyre then laid they the dead Hector, and when
the flames had consumed his body his comrades placed his white
bones in a golden urn, and over it with great stones did they raise a
mighty mound that all might see where he rested.
Yet still was the warfare between Greeks and Trojans not ended.
To Achilles death came in a shaft from the bow of Paris. By a
poisoned arrow driven at venture and at dark midnight from the bow
of an outcast leper was fair Paris slain. While winter snow lay white
on Ida, in Helen’s arms did his life ebb away.
Then came there a day when the Greeks burned their camp and
sailed homeward across the grey water.
Behind them they left a mighty horse of wood, and the men of
Troy came and drew it into the city as trophy and sign of victory over
those who had made it. But inside the horse were hidden many of
the bravest warriors of Greece, and at night, when the Trojans
feasted, the Greeks came out of their hiding-place and threw open
the gates.
And up from the sea came the Greek host, and in fire and in
blood fell the city of Troy.
Yet did not Helen perish. Back to his own kingdom by the sea
Menelaus took her, to reign, in peace, a queen, she who had brought
grief and death to so many, and to the city of Troy unutterable woe.
PRINTED IN GREAT BRITAIN
Transcriber’s Notes:
Quotes have been added on pages 11, 70, 78, 81 and
84, to conform to correct usage.
Illustrations have been moved up or down, as needed,
to avoid breaking the flow of paragraphs.
All hyphenation and spelling has been retained as
typeset.
*** END OF THE PROJECT GUTENBERG EBOOK STORIES
FROM THE ILIAD; OR, THE SIEGE OF TROY ***
Updated editions will replace the previous one—the old editions will
be renamed.
Creating the works from print editions not protected by U.S.
copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying copyright
royalties. Special rules, set forth in the General Terms of Use part of
this license, apply to copying and distributing Project Gutenberg™
electronic works to protect the PROJECT GUTENBERG™ concept
and trademark. Project Gutenberg is a registered trademark, and
may not be used if you charge for an eBook, except by following the
terms of the trademark license, including paying royalties for use of
the Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is very
easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.
START: FULL LICENSE
THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK
To protect the Project Gutenberg™ mission of promoting the free
distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.
Section 1. General Terms of Use and
Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund from
the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.
1.B. “Project Gutenberg” is a registered trademark. It may only be
used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law in
the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms of
this agreement by keeping this work in the same format with its
attached full Project Gutenberg™ License when you share it without
charge with others.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the terms
of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E. Unless you have removed all references to Project Gutenberg:
1.E.1. The following sentence, with active links to, or other
immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears, or
with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
1.E.2. If an individual Project Gutenberg™ electronic work is derived
from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.
1.E.3. If an individual Project Gutenberg™ electronic work is posted
with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning of
this work.
1.E.4. Do not unlink or detach or remove the full Project
Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.
1.E.5. Do not copy, display, perform, distribute or redistribute this
electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1 with
active links or immediate access to the full terms of the Project
Gutenberg™ License.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or expense
to the user, provide a copy, a means of exporting a copy, or a means
of obtaining a copy upon request, of the work in its original “Plain
Vanilla ASCII” or other form. Any alternate format must include the
full Project Gutenberg™ License as specified in paragraph 1.E.1.
1.E.7. Do not charge a fee for access to, viewing, displaying,
performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.
1.E.8. You may charge a reasonable fee for copies of or providing
access to or distributing Project Gutenberg™ electronic works
provided that:
• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You provide a full refund of any money paid by a user who
notifies you in writing (or by e-mail) within 30 days of receipt that
s/he does not agree to the terms of the full Project Gutenberg™
License. You must require such a user to return or destroy all
copies of the works possessed in a physical medium and
discontinue all use of and all access to other copies of Project
Gutenberg™ works.
• You provide, in accordance with paragraph 1.F.3, a full refund of
any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™
electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.
1.F.
1.F.1. Project Gutenberg volunteers and employees expend
considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.
1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except
for the “Right of Replacement or Refund” described in paragraph
1.F.3, the Project Gutenberg Literary Archive Foundation, the owner
of the Project Gutenberg™ trademark, and any other party
distributing a Project Gutenberg™ electronic work under this
agreement, disclaim all liability to you for damages, costs and
expenses, including legal fees. YOU AGREE THAT YOU HAVE NO
REMEDIES FOR NEGLIGENCE, STRICT LIABILITY, BREACH OF
WARRANTY OR BREACH OF CONTRACT EXCEPT THOSE
PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE THAT THE
FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.
1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you
discover a defect in this electronic work within 90 days of receiving it,
you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or entity
that provided you with the defective work may elect to provide a
replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.
1.F.4. Except for the limited right of replacement or refund set forth in
paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
1.F.5. Some states do not allow disclaimers of certain implied
warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.
1.F.6. INDEMNITY - You agree to indemnify and hold the
Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and distribution
of Project Gutenberg™ electronic works, harmless from all liability,
costs and expenses, including legal fees, that arise directly or
indirectly from any of the following which you do or cause to occur:
(a) distribution of this or any Project Gutenberg™ work, (b)
alteration, modification, or additions or deletions to any Project
Gutenberg™ work, and (c) any Defect you cause.
Section 2. Information about the Mission of
Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.
Volunteers and financial support to provide volunteers with the
assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.
Section 3. Information about the Project
Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.
The Foundation’s business office is located at 809 North 1500 West,
Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many small
donations ($1 to $5,000) are particularly important to maintaining tax
exempt status with the IRS.
The Foundation is committed to complying with the laws regulating
charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.
While we cannot and do not solicit contributions from states where
we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.
International donations are gratefully accepted, but we cannot make
any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Section 5. General Information About Project
Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
This website includes information about Project Gutenberg™,
including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.

More Related Content

Similar to Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning 2024 scribd download (20)

Programming iOS 5 2nd Edition Matt Neuburg
Programming iOS 5 2nd Edition Matt NeuburgProgramming iOS 5 2nd Edition Matt Neuburg
Programming iOS 5 2nd Edition Matt Neuburg
saertahai
 
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Obj...
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Obj...Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Obj...
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Obj...
thoramenzab0
 
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
joettealhadi
 
Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...
Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...
Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...
assangkaoua
 
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
jussiefathey
 
Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...
Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...
Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...
matbarnargis59
 
Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
heddaraduson
 
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
jungieaugi
 
Cocoa and Objective C Up and Running Foundations of Mac iPhone and iPod touch...
Cocoa and Objective C Up and Running Foundations of Mac iPhone and iPod touch...Cocoa and Objective C Up and Running Foundations of Mac iPhone and iPod touch...
Cocoa and Objective C Up and Running Foundations of Mac iPhone and iPod touch...
quizaloan
 
iOS 8 Swift Programming Cookbook Solutions Examples for iOS Apps 1st Edition ...
iOS 8 Swift Programming Cookbook Solutions Examples for iOS Apps 1st Edition ...iOS 8 Swift Programming Cookbook Solutions Examples for iOS Apps 1st Edition ...
iOS 8 Swift Programming Cookbook Solutions Examples for iOS Apps 1st Edition ...
matevurz
 
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad NahavandipooriOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
gancezatta3e
 
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad NahavandipooriOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
gancezatta3e
 
Beginning Ios Programming With Swift And Swiftui Ios 15 Simon Ng
Beginning Ios Programming With Swift And Swiftui Ios 15 Simon NgBeginning Ios Programming With Swift And Swiftui Ios 15 Simon Ng
Beginning Ios Programming With Swift And Swiftui Ios 15 Simon Ng
elhmedsmirat
 
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
exzanyangdi
 
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
mycielyonne
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
Manoj Ellappan
 
Ios development training presentation
Ios development training presentationIos development training presentation
Ios development training presentation
Deepak S
 
iOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. LimiOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. Lim
bambildurdle
 
iOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. LimiOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. Lim
laczaididdle
 
Reinvent yourself - How to become a native iOS developer in nine steps
Reinvent yourself - How to become a native iOS developer in nine stepsReinvent yourself - How to become a native iOS developer in nine steps
Reinvent yourself - How to become a native iOS developer in nine steps
Jason Hanson
 
Programming iOS 5 2nd Edition Matt Neuburg
Programming iOS 5 2nd Edition Matt NeuburgProgramming iOS 5 2nd Edition Matt Neuburg
Programming iOS 5 2nd Edition Matt Neuburg
saertahai
 
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Obj...
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Obj...Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Obj...
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Obj...
thoramenzab0
 
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
joettealhadi
 
Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...
Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...
Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...
assangkaoua
 
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
jussiefathey
 
Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...
Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...
Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...
matbarnargis59
 
Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
Ios 4 Programming Cookbook Solutions Examples For Iphone Ipad And Ipod Touch ...
heddaraduson
 
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
jungieaugi
 
Cocoa and Objective C Up and Running Foundations of Mac iPhone and iPod touch...
Cocoa and Objective C Up and Running Foundations of Mac iPhone and iPod touch...Cocoa and Objective C Up and Running Foundations of Mac iPhone and iPod touch...
Cocoa and Objective C Up and Running Foundations of Mac iPhone and iPod touch...
quizaloan
 
iOS 8 Swift Programming Cookbook Solutions Examples for iOS Apps 1st Edition ...
iOS 8 Swift Programming Cookbook Solutions Examples for iOS Apps 1st Edition ...iOS 8 Swift Programming Cookbook Solutions Examples for iOS Apps 1st Edition ...
iOS 8 Swift Programming Cookbook Solutions Examples for iOS Apps 1st Edition ...
matevurz
 
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad NahavandipooriOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
gancezatta3e
 
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad NahavandipooriOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor
gancezatta3e
 
Beginning Ios Programming With Swift And Swiftui Ios 15 Simon Ng
Beginning Ios Programming With Swift And Swiftui Ios 15 Simon NgBeginning Ios Programming With Swift And Swiftui Ios 15 Simon Ng
Beginning Ios Programming With Swift And Swiftui Ios 15 Simon Ng
elhmedsmirat
 
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
exzanyangdi
 
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
iOS 9 Programming Fundamentals with Swift Swift Xcode and Cocoa Basics 2nd Ed...
mycielyonne
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
Manoj Ellappan
 
Ios development training presentation
Ios development training presentationIos development training presentation
Ios development training presentation
Deepak S
 
iOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. LimiOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. Lim
bambildurdle
 
iOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. LimiOS 7 in Action 1st Edition Brendan G. Lim
iOS 7 in Action 1st Edition Brendan G. Lim
laczaididdle
 
Reinvent yourself - How to become a native iOS developer in nine steps
Reinvent yourself - How to become a native iOS developer in nine stepsReinvent yourself - How to become a native iOS developer in nine steps
Reinvent yourself - How to become a native iOS developer in nine steps
Jason Hanson
 

Recently uploaded (20)

IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
Critical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi MosesCritical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi Moses
Excellence Foundation for South Sudan
 
How to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guidesHow to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guides
Celine George
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
How to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 WebsiteHow to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 Website
Celine George
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ..."Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
Arshad Shaikh
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
Pragya Champion's Chalice 2025 Set , General Quiz
Pragya Champion's Chalice 2025 Set , General QuizPragya Champion's Chalice 2025 Set , General Quiz
Pragya Champion's Chalice 2025 Set , General Quiz
Pragya - UEM Kolkata Quiz Club
 
K-Circle-Weekly-Quiz-May2025_12345678910
K-Circle-Weekly-Quiz-May2025_12345678910K-Circle-Weekly-Quiz-May2025_12345678910
K-Circle-Weekly-Quiz-May2025_12345678910
PankajRodey1
 
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptxQUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
Sourav Kr Podder
 
LDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-inLDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-in
LDM & Mia eStudios
 
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo SlidesHow to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
Celine George
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
muneebrana3215
 
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
Arshad Shaikh
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
Introduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdfIntroduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdf
CME4Life
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
How to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guidesHow to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guides
Celine George
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
How to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 WebsiteHow to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 Website
Celine George
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ..."Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
Arshad Shaikh
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
K-Circle-Weekly-Quiz-May2025_12345678910
K-Circle-Weekly-Quiz-May2025_12345678910K-Circle-Weekly-Quiz-May2025_12345678910
K-Circle-Weekly-Quiz-May2025_12345678910
PankajRodey1
 
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptxQUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
Sourav Kr Podder
 
LDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-inLDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-in
LDM & Mia eStudios
 
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo SlidesHow to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
Celine George
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
muneebrana3215
 
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
Arshad Shaikh
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
Introduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdfIntroduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdf
CME4Life
 

Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning 2024 scribd download

  • 1. Full download textbook at textbookfull.com Learning Swift Building Apps for OSX, iOS, and Beyond Jon Manning https://textbookfull.com/product/learning-swift- building-apps-for-osx-ios-and-beyond-jon-manning/ Download more textbook from https://textbookfull.com
  • 2. More products digital (pdf, epub, mobi) instant download maybe you interests ... Learning Swift: Building Apps for macOS, iOS, and Beyond 2nd Edition Paris Buttfield-Addison https://textbookfull.com/product/learning-swift-building-apps- for-macos-ios-and-beyond-2nd-edition-paris-buttfield-addison/ Biota Grow 2C gather 2C cook Loucas https://textbookfull.com/product/biota-grow-2c-gather-2c-cook- loucas/ iOS 11 Swift Programming Cookbook Solutions and Examples for iOS Apps 1st Edition Vandad Nahavandipoor https://textbookfull.com/product/ios-11-swift-programming- cookbook-solutions-and-examples-for-ios-apps-1st-edition-vandad- nahavandipoor/ Swift 4 for Absolute Beginners: Develop Apps for iOS 4th Edition Stefan Kaczmarek https://textbookfull.com/product/swift-4-for-absolute-beginners- develop-apps-for-ios-4th-edition-stefan-kaczmarek/
  • 3. Head First Swift 1st Edition Gray Anthony Manning Jon Buttfield Addison Paris https://textbookfull.com/product/head-first-swift-1st-edition- gray-anthony-manning-jon-buttfield-addison-paris/ Developing Inclusive Mobile Apps: Building Accessible Apps for iOS and Android 1st Edition Rob Whitaker https://textbookfull.com/product/developing-inclusive-mobile- apps-building-accessible-apps-for-ios-and-android-1st-edition- rob-whitaker/ iOS 10 SDK Development Creating iPhone and iPad Apps with Swift Chris Adamson https://textbookfull.com/product/ios-10-sdk-development-creating- iphone-and-ipad-apps-with-swift-chris-adamson/ iOS Unit Testing by Example XCTest Tips and Techniques Using Swift 1st Edition Jon Reid https://textbookfull.com/product/ios-unit-testing-by-example- xctest-tips-and-techniques-using-swift-1st-edition-jon-reid/ Learn Swift by Building Applications Explore Swift programming through iOS app development 1st Edition Emil Atanasov https://textbookfull.com/product/learn-swift-by-building- applications-explore-swift-programming-through-ios-app- development-1st-edition-emil-atanasov/
  • 6. Jon Manning, Paris Buttfield-Addison, and Tim Nugent Learning Swift 3 Boston Farnham Sebastopol Tokyo Beijing Boston Farnham Sebastopol Tokyo Beijing
  • 7. 978-1-491-96699-0 [FILL IN] Learning Swift 3 by Paris Buttfield-Addison , Jon Manning , and Tim Nugent Copyright © 2016 Secret Lab. 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://safaribooksonline.com ). For more information, contact our corporate/ institutional sales department: 800-998-9938 or [email protected] . Editor: Rachel Roumeliotis Production Editor: FILL IN PRODUCTION EDI‐ TOR Copyeditor: FILL IN COPYEDITOR Proofreader: FILL IN PROOFREADER Indexer: FILL IN INDEXER Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Rebecca Demarest January -4712: First Edition Revision History for the First Edition 2016-12-05: First Early Release See http://oreilly.com/catalog/errata.csp?isbn=9781491966990 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning Swift 3, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. While the publisher and the author(s) have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author(s) disclaim all responsibil‐ ity 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.
  • 8. Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Part I. Swift Basics 1. Getting Started. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 The Apple Developer Program 5 Registering for the Apple Developer Program 6 Downloading Xcode 7 Creating Your First Project with Xcode 8 The Xcode Interface 12 Developing a Simple Swift Application 20 Designing the Interface 21 Connecting the Code 22 Using the iOS Simulator 24 Conclusion 26 2. The Basics of Swift. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 The Swift Programming Language 28 Swift 2 Versus Swift 3 30 Playgrounds 31 Comments 32 Variables and Constants 33 Operators 34 Control Flow 35 Loops 36 Switches 37 Types 40 iii
  • 9. Working with Strings 40 Comparing Strings 41 Searching Strings 42 Optional Types 42 Type Casting 44 Tuples 45 Arrays 46 Dictionaries 48 Enumerations 48 Sets 50 Functions and Closures 51 Using Functions as Variables 54 Closures 56 The defer Keyword 58 The guard Keyword 58 Making your code Swifty 59 Conclusion 59 3. Swift for Object-Oriented App Development. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Classes and Objects 61 Initialization and Deinitialization 63 Properties 64 Inheritance 64 Protocols 68 Extensions 69 Access Control 70 Operator Overloading 72 Generics 73 Subscripts 74 Structures 75 Modules 76 The Swift Standard Library, Foundation, Cocoa, and Cocoa Touch 76 Swift Package Manager 77 Data 79 Loading Data from Files and URLs 79 Serialization and Deserialization 80 Error Handling 81 Memory Management 84 Design Patterns in Cocoa and Cocoa Touch 85 Model-View-Controller 85 Delegation 87 Structuring an App 89 iv | Table of Contents
  • 10. The Application Delegate 89 Window Controllers and View Controllers 89 Nibs and Storyboards 90 Conclusion 90 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Part II. An OS X App 4. Setting Up the OS X Notes App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Designing the OS X Notes App 124 Creating the OS X Project 127 Defining a Document Type 132 Adding the Icon 136 Conclusion 138 5. Working with Documents on OS X. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 The NSDocument Class 139 Storing Data in the Document 140 Storing Text 141 Package File Formats 142 The guard Keyword, and Why It’s Great 147 Saving Files 148 Loading Files 151 A Basic UI 154 Conclusion 162 6. User Interfaces and iCloud. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Updating the UI 163 Document-Filetype-Extension UI 167 Getting an Icon for the Collection View Cells 172 Adding Attachments 174 Storing and Managing Attachments 182 Displaying Data in the Collection View 190 Enhancing Attachments 193 Opening Attachments 193 JSON Attachments 197 Adding Attachments via Drag-and-Drop 202 Adding QuickLook 207 iCloud 213 The Basics of iCloud 214 Table of Contents | v
  • 11. Conclusion 217 Part III. An iOS App 7. Setting Up the iOS Notes App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 Designing the iOS Notes App 222 Creating the iOS Project 228 Enabling the iOS App for iCloud 232 Defining a Document Type 236 Conclusion 238 8. Working with Files in iCloud. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 The App Sandbox 239 iCloud Availability 241 Creating the Document List View Controller 242 View Controllers and Storyboards 244 The Navigation Controller 244 Collection Views 248 Using Constraints to Control Size and Position 250 Creating the Document Class 254 Listing Documents 260 Creating Documents 270 Downloading from iCloud 272 Deleting Documents 276 Renaming Documents 283 Conclusion 286 9. Working with Documents on iOS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 Adding a View to Display Notes 289 Editing and Saving Documents 297 Conclusion 299 10. Working with Files and File Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 Setting Up the Interface for Attachments 301 Listing Attachments 305 Determining Types of Attachments 307 Displaying Attachment Cells 310 Dealing with Conflicts 316 Creating the Quick Look Thumbnail 322 Conclusion 325 vi | Table of Contents
  • 12. 11. Images and Deletion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 Adding Attachments 327 Adding Image Attachments 329 Viewing Attachments 335 Deleting Attachments 346 Conclusion 353 12. Supporting the iOS Ecosystem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 Sharing with UIActivityController 355 Handoffs 358 Searchability 363 Conclusion 365 13. Extending iOS Apps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367 Searching with a Spotlight Indexing Extension 368 Conclusion 378 14. Multimedia and Location attachments]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379 Audio Attachments 379 Video Attachments 392 Location Attachment 400 Conclusion 404 15. Polishing the iOS App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405 Opening Links in SFSafariViewController 405 3D Touch 409 Home Screen Quick Actions 410 Peek and Pop 413 Settings 414 Undo Support 416 Images with Filters 419 Worldwide Apps 423 Internationalization 424 Localization 427 Accessibility 432 Splitscreen Multitasking 437 Conclusion 438 Table of Contents | vii
  • 13. Part IV. Extending Your Apps 16. Building a watchOS App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441 Designing for the Watch 442 Designing Our watchOS App 444 Creating the watchOS Extension 446 Communicating with the iPhone 450 User Interfaces for the Apple Watch 469 Showing Note Contents 475 Creating New Notes 482 Adding Handoff Between the Watch and the iPhone 485 Glances 490 Conclusion 494 17. Code Quality and Distribution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495 Debugging 495 Instruments 498 Testing 503 Unit Testing 504 UI Testing 506 Using Objective-C and Swift in the Same Project 508 Using Swift Objects in Objective-C 508 Using Objective-C Objects in Swift 509 The App Store 510 App Thinning 511 Testing iOS Apps with TestFlight 512 Conclusion 513 viii | Table of Contents
  • 14. Preface Welcome to Learning Swift 3! This book will help you put the Swift programming language into practice by walking you through the development of a note-taking application for the Apple iOS, OS X, and watchOS platforms. Swift is a pretty amazing modern language, taking the best from other newer lan‐ guages without reinventing the wheel. Swift is easy to write, easy to read, and really hard to make mistakes in. Our philosophy is that the best way to learn Swift is to build apps using it! To build apps, though, you need a great framework, and Apple has several: Cocoa, Cocoa Touch, and WatchKit, to name only a few. This book could quite easily be titled Learning Cocoa and Cocoa Touch with Swift, or something similar, because the frame‐ works are just as important as the language itself. At the time of writing, Swift is cur‐ rently at version 3, and has a bright future ahead of it. Resources Used in This Book We recommend following the book by writing code yourself as you progress through each chapter. If you get stuck, or just want to archive a copy of the code, you can find what you need via our website. As this book teaches you how to build a real-world app, we primarily focus on show‐ ing you the coding side of things. We’re not going to ask you to paint your own icons, so we’ve provided them for you. You can also download them from our website. Audience and Approach This book is solely focused on Swift 3 and does not cover the use of Objective-C. We might mention it occasionally, but we don’t expect you to know how to use it. We first cover the basics of the Swift 3 language, and then move on to teach as much of the language as we can, as well as the use of the Cocoa, Cocoa Touch, and watchOS ix
  • 15. frameworks, through the construction of a complete app for both OS X and iOS. As a reminder, Swift is the programming language, Cocoa is the framework for OS X apps, Cocoa Touch is the framework for iOS apps, and somewhat predictably, watchOS is the framework for the Apple Watch. This book’s approach differs from that of other programming books that you may have encountered. As we’ve mentioned, we believe that the best way to learn Swift is to build apps using it. We assume that you’re a reasonably capable programmer, but we don’t assume you’ve ever developed for iOS or OS X, or used Swift or Objective-C before. We also assume that you’re fairly comfortable navigating OS X and iOS as a user. Organization of This Book In this book, we’ll be talking about Cocoa and Cocoa Touch, the frameworks used on OS X and iOS, respectively. Along the way, we’ll also be covering Swift, including its syntax and features. In Part I, Swift Basics, we begin with a look at the tools used for programming with Swift, as well as the Apple Developer Program. Then we move on to the basics of the Swift programming language and structuring a program for Apple’s platforms, as well as common design patterns. Chapter 1 covers the basics of Apple’s developer program, and guides you through a simple Swift app. Chapter 2 explores all the basics of Swift, and prepares you for using it to build more complex applications. Chapter 3 discusses Swift’s object-oriented features, as well as the structure of a good app. In Part II, An OS X App, we build a simple note-taking application for Macs, target‐ ing OS X. Along the way, we discuss the design of the app, how it’s structured, how it uses documents, and how to build all the features. Chapter 4 starts off our OS X notes app, and sets up the document model, and icon. Chapter 5 goes into detail on working with documents in OS X apps. Chapter 6 connects the app to iCloud, and finishes up the OS X app. In Part III, An iOS App, we build a fully featured iOS note-taking application as a companion for the OS X app from Part II. Chapter 7 starts off our iOS app, and sets up the same document model for iOS. Chapter 8 connects the iOS app to iCloud. x | Preface
  • 16. Chapter 9 creates an interface on iOS for displaying our notes. Chapter 10 sets up the iOS app to handle attachments. Chapter 11 adds image support to the iOS app. Chapter 12 adds sharing and searching support to the iOS app. Chapter 13 adds a today widget to the iOS app. Chapter 14 adds location, audio, video, and contact attachments to the iOS app, as well as notifications. Chapter 15 finishes the iOS app with a whole lot of polish! In Part IV, Extending Your Apps, we add a watchOS app, and explore bug hunting and performance tuning. Chapter 16 adds a watchOS app to the iOS app, allowing for Apple Watch support. Chapter 17 explores debugging and performance tuning. 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 | xi
  • 17. This element signifies a general note. This element indicates a warning or caution. Using Code Examples Supplemental material (code examples, exercises, errata, etc.) is available for down‐ load at our website. 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: “Learning Swift by Jonathon Man‐ ning, Paris Buttfield-Addison, and Tim Nugent (O’Reilly). Copyright 2016 Secret Lab, 978-1-491-94074-7.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at [email protected]. Safari® Books Online Safari Books Online is an on-demand digital library that deliv‐ ers expert content in both book and video form from the world’s leading authors in technology and business. Technology professionals, software developers, web designers, and business and crea‐ tive professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training. xii | Preface
  • 18. Safari Books Online offers a range of plans and pricing for enterprise, government, education, and individuals. Members have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kauf‐ mann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and hundreds more. For more information about Safari Books Online, please visit us online. 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/learning-swift. To comment or ask technical questions about this book, send email to bookques‐ [email protected]. 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 Acknowledgments Jon thanks his mother, father, and the rest of his crazily extended family for their tre‐ mendous support. Paris thanks his mother, without whom he wouldn’t be doing anything nearly as interesting, let alone writing books. Tim thanks his parents and family for putting up with his rather lackluster approach to life. Preface | xiii
  • 19. We’d all like to thank our editors, Rachel Roumeliotis and Brian MacDonald—their skill and advice were invaluable to completing the book. Likewise, all the O’Reilly Media staff we’ve interacted with over the course of writing the book have been the absolute gurus of their fields. A huge thank you to Tony Gray and the Apple University Consortium (AUC) for the monumental boost they gave us and others listed on this page. We wouldn’t be writ‐ ing this book if it weren’t for them. And now you’re writing books, too, Tony—sorry about that! Thanks also to Neal Goldstein, who deserves full credit and/or blame for getting us into the whole book-writing racket. We’re thankful for the support of the goons at MacLab (who know who they are and continue to stand watch for Admiral Dolphin’s inevitable apotheosis), as well as pro‐ fessor Christopher Lueg, Dr. Leonie Ellis, and the rest of the staff at the University of Tasmania for putting up with us. “Apologies” to Mark Pesce. He knows why. Additional thanks to Rex S., Nic W., Andrew B., Jess L., and Ash J., for a wide variety of reasons. And very special thanks to Steve Jobs, without whom this book (and many others like it) would not have reason to exist. Thanks also to our tech reviewers, with special thanks to Chris Devers and Tony Gray for their thoroughness and professionalism. Finally, thank you very much for buying our book—we appreciate it! And if you have any feedback, please let us know. You can email us at [email protected] and find us on Twitter @thesecretlab. xiv | Preface
  • 22. CHAPTER 1 Getting Started This book is a work-in-progress. We will be releasing regular Early Release editions, with a final version late in 2016. The book may be inconsistent, out of date, or incomplete until then. Please let us know if you have any feedback by emailing learningswift@secret‐ lab.com.au This book teaches the Swift 3 programming language by exploring the development of three applications for Apple platforms: OS X, iOS, and watchOS. This book’s approach might differ from what you’re used to, because our philosophy is that the best way to learn Swift is to build apps using it! The vast majority of the code in this book will be part of the apps we’re building—a full note-taking app for OS X, iOS, and watchOS—rather than individual pieces of sample code. You can see the final product in Figure 1-1. 3
  • 23. Figure 1-1. Our finished app, for OS X, iOS, and watchOS Our app is fully functional, but we do make some deliberate design and feature deci‐ sions along the way to constrain the scope a little (the book is more than 500 pages!). As we mentioned in the preface, we assume that you’re a reasonably capable pro‐ grammer, but we don’t assume you’ve ever developed for iOS or OS X, or used Swift or Objective-C before. We also assume that you’re fairly comfortable navigating OS X and iOS as a user. We recommend that you work through this book front to back, building the OS X app, then the iOS app, then the watchOS app, even if you’re only interested in one of the platforms. By approach‐ ing the book this way, you’ll get the best understanding of what building a real app with Swift requires. Programming with Swift, and using the Cocoa and Cocoa Touch frameworks to develop OS X and iOS apps, respectively, involves using a set of tools developed by Apple. In this chapter, you’ll learn about these tools, where to get them, how to use them, how they work together, and what they can do. At the end of this chapter, you’ll make a very simple Swift application for iOS, before we dive into the details of the Swift language and Apple’s frameworks in the following two chapters. 4 | Chapter 1: Getting Started
  • 24. The Apple development tools have a long and storied history. Orig‐ inally a set of standalone application tools for the NeXTSTEP OS, they were eventually adopted by Apple for use as the official OS X tools. Later, Apple largely consolidated them into one application, known as Xcode, though some of the applications (such as Instru‐ ments and the iOS simulator) remain somewhat separate, owing to their relatively peripheral role in the development process. You’ll notice the prefix NS on many of the classes you use for Cocoa and Cocoa Touch development with Swift. This prefix comes from the NeXTSTEP heritage of many of Apple’s frameworks. In addition to the development tools, Apple offers developers a paid membership in its Developer Program, which provides resources and support. The program allows access to online developer forums and specialized technical support for those interes‐ ted in talking to the framework engineers. If you are just interested in learning Swift and exploring the development tools, you can do so for free. You will need a paid membership, however, if you wish to use developer services like iCloud in your apps, or to distribute anything you build through either the iOS or OS X App Store. Swift is open source, but this doesn’t really mean much when it comes to using it to develop apps for OS X, iOS, and watchOS. There’s an excellent community of people working on the language that you can find at the Swift website. With the introduction of Apple’s curated App Stores for OS X, iOS, and watchOS, as well as emerging Apple platforms like tvOS, the Developer Program has become the official way for developers to provide their credentials when submitting applications to Apple—in essence, it is your ticket to selling apps through Apple. In this chapter, you’ll learn how to sign up for the Apple Developer Program, as well as how to use Xcode, the development tool used to build apps in Swift. The Apple Developer Program The paid Apple Developer Program provides access to beta development tools, beta operating system releases, and distribution ability through Apple’s App Stores. It also allows you to use some of the cloud-dependent features of the platforms, such as iCloud, CloudKit, In-App Purchase, Maps, and App Groups. We will be using a lot of cloud-dependent features, including Maps and iCloud, in the apps we build throughout this book. You will not be able to run these apps if you do not have a paid member‐ ship. The Apple Developer Program | 5
  • 25. It isn’t necessary to be a member of the Apple Developer Program if you don’t intend to submit apps to the App Stores, or don’t need the cloud-dependent features. We strongly recommend joining, though, if you intend to build apps for any of Apple’s platforms, as the other benefits are substantial: • Access to the Apple Developer Forums, which are frequented by Apple engineers and designed to allow you to ask questions of your fellow developers and the people who wrote the OS. • Access to beta versions of the OS before they are released to the public, which enables you to test your applications on the next version of the OS X, iOS, watchOS, and tvOS platforms, and make necessary changes ahead of time. You also receive beta versions of the development tools. • A digital signing certificate (one for each platform) used to identify you to the App Stores. Without this, you cannot submit apps to the App Store, making a membership mandatory for anyone who wants to release software either for free or for sale via an App Store. That said, registering for the Developer Program isn’t necessary to view the docu‐ mentation or to download the current version of the developer tools, so you can play around with writing apps without opening your wallet. Registering for the Apple Developer Program To register for the Developer Program, you’ll first need an Apple ID. It’s quite likely that you already have one, as the majority of Apple’s online services require one to identify you. If you’ve ever used iCloud, the iTunes store (for music or apps), or Apple’s support and repair service, you already have an ID. You might even have more than one (one of this book’s authors has four). If you don’t yet have an ID, you’ll create one as part of the registration process. When you register for the Developer Program, the membership gets added to your Apple ID. If you don’t want to register for the paid developer program, you can skip to “Downloading Xcode” on page 7 for instructions on installing Xcode, the developer tools. Once again, keep in mind that you won’t be able to build the apps that we teach in this book if you don’t have a paid membership, as we use cloud-dependent features such as iCloud and Maps. There are alternatives to many of Apple’s tools—such as the Google Maps SDK for iOS, or cloud-storage services from Amazon and Microsoft. However, you’ll still need a paid membership through Apple to put apps in the iTunes App Store. 6 | Chapter 1: Getting Started
  • 26. Once you’re on the Apple Developer Program website, simply click Enroll, and follow the steps to enroll. You can choose to register as an individual or as a company. If you register as an indi‐ vidual, your apps will be sold under your name. If you register as a company, your apps will be sold under your company’s legal name. Choose carefully, as it’s very diffi‐ cult to convince Apple to change your program’s type. If you’re registering as an individual, you’ll just need your credit card. If you’re regis‐ tering as a company, you’ll need your credit card as well as documentation that proves you have authority to bind your company to Apple’s terms and conditions. For information on code signing and using Xcode to test and run your apps on your own physical devices, see Apple’s App Distribu‐ tion Guide. We don’t cover this in the book, as it’s a process that changes often. Apple usually takes about 24 hours to activate an account for individuals, and longer for companies. Once you’ve received confirmation from Apple, you’ll be emailed a link to activate your account; when that’s done, you’re a full-fledged developer! Downloading Xcode To develop apps for either platform, you’ll use Xcode, Apple’s integrated development environment. Xcode combines a source code editor, debugger, compiler, profiler, iOS simulator, Apple Watch simulator, and more into one package. It’s where you’ll spend the majority of your time when developing applications. At the time of writing, Xcode is only available for Mac, but who knows what the future holds for the iPad Pro? You can get Xcode from the Mac App Store. Simply open the App Store application and search for “Xcode,” and it’ll pop up. It’s a free download, though it’s rather large (several gigabytes at the time of writing). Once you’ve downloaded Xcode, it’s straightforward enough to install it. The Mac App Store gives you an application that on first launch sets up everything you need to use Xcode. Just launch the downloaded app, and follow the prompts, and you’ll be up and running in no time. The Apple Developer Program | 7
  • 27. This book covers Swift 3, which is available only if you’re using Xcode 7 or later. Make sure you’re using the latest version of Xcode from the Mac App Store. It’s good practice to use the latest Xcode at all times. Creating Your First Project with Xcode Xcode is designed around a single window. Each of your projects will have one win‐ dow, which adapts to show what you’re working on. To start exploring Xcode, you’ll first need to create a project by following these steps: 1. Launch Xcode. You can find it by opening Spotlight (by pressing ⌘-space bar) and typing Xcode. You can also find it by opening the Finder, going to your hard drive, and opening the Applications directory. If you had any projects open previ‐ ously, Xcode will open them for you. Otherwise, the Welcome to Xcode screen appears (see Figure 1-2). Figure 1-2. The Welcome to Xcode screen 2. Create a new project by clicking “Create a new Xcode project” or go to File→New→Project. You’ll be asked what kind of application to create. The template selector is divi‐ ded into two areas. On the lefthand side, you’ll find a collection of application categories. You can choose to create an iOS, watchOS, or OS X application from the project templates, which will set up a project directory to get you started. 8 | Chapter 1: Getting Started
  • 28. Because we’re just poking around Xcode at the moment, it doesn’t really matter what we select, so choose Application under the iOS header and select Single View Application. This creates an empty iOS application and displays the project settings window shown in Figure 1-3. Figure 1-3. The project settings window 3. Name the application. Enter HelloSwift in the Product Name section. 4. Enter information about the project. Depending on the kind of project template you select, you’ll be asked to provide different information about how the new project should be configured. At a minimum, you’ll be asked for the following information, no matter which platform and template you choose: The product’s name This is the name of the project and is visible to the user. You can change this later. Your organization’s name This is the name of your company or group. It’s not directly used by Xcode, but new source code files that you create will mention it. Creating Your First Project with Xcode | 9
  • 29. Your organization identifier This is used to generate a bundle ID, a string that looks like a reverse domain name (e.g., if O’Reilly made an application named MyUsefulApplication, the bundle ID would be com.oreilly.MyUsefulApplication). Bundle IDs are the unique identifier for an application, and are used to identify that app to the system and to the App Store. Because each bundle ID must be unique, the same ID can’t be used for more than one application in either of the iOS or Mac App Stores. That’s why the for‐ mat is based on domain names—if you own the site use‐ fulsoftware.com, all of your bundle IDs would begin with com.usefulsoftware, and you won’t accidentally use a bun‐ dle ID that someone else is using or wants to use because nobody else owns the same domain name. If you don’t have a domain name, enter anything you like, as long as it looks like a backward domain name (e.g., com.mycompany will work). If you plan on releasing your app, either to the App Store or elsewhere, it’s very important to use a company identi‐ fier that matches a domain name you own. The App Store requires it, and the fact that the operating system uses the bundle ID that it generates from the company identifier means that using a domain name that you own eliminates the possibility of accidentally creating a bundle ID that conflicts with someone else’s. If you’re writing an application for the Mac App Store, you’ll also be prompted for the App Store category (whether it’s a game, an educational app, a social net‐ working app, or something else). Depending on the template, you may also be asked for other information (e.g., the file extension for your documents if you are creating a document-aware application, such as a Mac app). You’ll also be asked which language you want to use; because this book is about Swift, you should probably choose Swift! The additional information needed for this project is covered in the following steps. 5. Make the application run on the iPhone by choosing iPhone from the Devices drop-down list. 10 | Chapter 1: Getting Started
  • 30. iOS applications can run on the iPad, iPhone, or both. Appli‐ cations that run on both are called “universal” applications and run the same binary but have different user interfaces. For this exercise, just choose iPhone. You should be building universal iOS apps, in general, and we’ll be doing that when we properly start on iOS, in Part III. 6. Leave the rest of the settings as shown in Figure 1-4. Click Next to create the project. Figure 1-4. The project settings 7. Choose where to save the project. Select a location that suits you. We recommend putting all your work related to this book (and other Swift programming learning you might do) in one folder. You might notice a little checkbox for Source Con‐ trol; this creates a source code control repository for your code, giving you a place where you can save and manage different versions of your code as you cre‐ ate them. While in general this is a good idea to use, for this example project, make sure this is unchecked. Once you’ve done this, Xcode will open the project, and you can now start using the entire Xcode interface, as shown in Figure 1-5. Creating Your First Project with Xcode | 11
  • 31. Figure 1-5. The entire Xcode interface The Xcode Interface As mentioned, Xcode shows your entire project in a single window, which is divided into a number of sections. You can open and close each section at will, depending on what you want to see. Let’s take a look at each of these sections and examine what they do. The editor The Xcode editor (Figure 1-6) is where you’ll be spending most of your time. All source code editing, interface design, and project configuration take place in this sec‐ tion of the application, which changes depending on which file you have open. If you’re editing source code, the editor is a text editor, with code completion, syntax highlighting, and all the usual features that developers have come to expect from an integrated development environment. If you’re modifying a user interface, the editor becomes a visual editor, allowing you to drag around the components of your inter‐ face. Other kinds of files have their own specialized editors as well. When you first create a project, the editor will start by showing the project settings, as seen in Figure 1-6. 12 | Chapter 1: Getting Started
  • 32. Figure 1-6. Xcode’s editor, showing the project settings The editor can also be split into a main editor and an assistant editor through the edi‐ tor selector. The assistant shows files that are related to the file open in the main edi‐ tor. It will continue to show files that have a relationship to whatever is open, even if you open different files. For example, if you open an interface file and then open the assistant, the assistant will, by default, show related code for the interface you’re editing. If you open another interface file, the assistant will show the code for the newly opened files. At the top of the editor, you’ll find the jump bar. The jump bar lets you quickly jump from the content that you’re editing to another piece of related content, such as a file in the same folder. The jump bar is a fast way to navigate your project. The toolbar The Xcode toolbar (Figure 1-7) acts as mission control for the entire interface. It’s the only part of Xcode that doesn’t significantly change as you develop your applications, and it serves as the place where you can control what your code is doing. Figure 1-7. Xcode’s toolbar From left to right, after the OS X window controls, the toolbar features the following items: Run button (Figure 1-8) Clicking this button instructs Xcode to compile and run the application. Creating Your First Project with Xcode | 13
  • 33. Another random document with no related content on Scribd:
  • 34. ‘Choked is my stream with dead men!’ it cried, ‘and still thou slayest!’ But when Achilles heeded not, in fierce flood the river uprose against him, sweeping the slain before it, and in furious spate seeking to destroy Achilles. But as its waves smote against his shield, Achilles grasped a tall elm, and uprooting it, cast it into the river to dam the torrent. For the moment only was the angry river stayed. In fear did Achilles flee across the plain, but with a mighty roar it pursued him, and caught him. To the gods then cried Achilles, and to his aid came Athene, and close to the walls of Troy again did Achilles chase the Trojan men. From the city walls old Priam saw the dreadful things Achilles wrought. And when, his armour blazing like the brightest stars of the sky, he drew near, and Hector would have gone to meet him, in grief did Priam cry to his dearly-loved son: ‘Hector, beloved son, I pray thee go not alone to meet this man; mightier far than thou is he.’ But all eager for the fight was Hector. Of all the men of Troy he alone still stood unafraid. Then did the mother of Hector beseech him to hold back from what must surely mean death. Yet Hector held not back, but on his shining shield leaned against a tower, awaiting the coming of the great destroyer. And at last they met, face to face, spear to spear. As a shooting- star in the darkness so flashed the spear of Achilles as he hurled it home to pierce the neck of Hector. Gods and men had deserted Hector, and alone before the walls of Troy he fell and died. Thus ended the fight. For twelve days did the Greek host rejoice, and all through the days Hector’s body lay unburied. For at the heels of swift horses had the Greeks dragged him to the ships, while from the battlements his
  • 35. mother and his wife Andromache watched, wailing in agony, with hearts that broke. The shadow of death came down upon Hector (page 116) Then at length went old Priam to the camp of the Greeks. And before Achilles he fell, beseeching him to have mercy and to give him back the body of his son. So was the heart of Achilles moved, and the body of Hector ransomed; and with wailing of women did the people of Troy
  • 36. welcome home their hero. Over him lamented his old mother, for of all her sons was he to her most dear, and over him wept, with burning tears, his wife Andromache. And to his bier came Helen, and with breaking heart did she sob forth her sorrow. ‘Dearest of my brothers,’ she said, ‘from thee have I heard neither reproach nor evil word. With kind words and gentle heart hast thou ever stood by me. Lost, lost is my one true friend. No more in Troyland is any left to pity me.’ On lofty funeral pyre then laid they the dead Hector, and when the flames had consumed his body his comrades placed his white bones in a golden urn, and over it with great stones did they raise a mighty mound that all might see where he rested. Yet still was the warfare between Greeks and Trojans not ended. To Achilles death came in a shaft from the bow of Paris. By a poisoned arrow driven at venture and at dark midnight from the bow of an outcast leper was fair Paris slain. While winter snow lay white on Ida, in Helen’s arms did his life ebb away. Then came there a day when the Greeks burned their camp and sailed homeward across the grey water. Behind them they left a mighty horse of wood, and the men of Troy came and drew it into the city as trophy and sign of victory over those who had made it. But inside the horse were hidden many of the bravest warriors of Greece, and at night, when the Trojans feasted, the Greeks came out of their hiding-place and threw open the gates. And up from the sea came the Greek host, and in fire and in blood fell the city of Troy. Yet did not Helen perish. Back to his own kingdom by the sea Menelaus took her, to reign, in peace, a queen, she who had brought
  • 37. grief and death to so many, and to the city of Troy unutterable woe. PRINTED IN GREAT BRITAIN
  • 38. Transcriber’s Notes: Quotes have been added on pages 11, 70, 78, 81 and 84, to conform to correct usage. Illustrations have been moved up or down, as needed, to avoid breaking the flow of paragraphs. All hyphenation and spelling has been retained as typeset.
  • 39. *** END OF THE PROJECT GUTENBERG EBOOK STORIES FROM THE ILIAD; OR, THE SIEGE OF TROY *** Updated editions will replace the previous one—the old editions will be renamed. Creating the works from print editions not protected by U.S. copyright law means that no one owns a United States copyright in these works, so the Foundation (and you!) can copy and distribute it in the United States without permission and without paying copyright royalties. Special rules, set forth in the General Terms of Use part of this license, apply to copying and distributing Project Gutenberg™ electronic works to protect the PROJECT GUTENBERG™ concept and trademark. Project Gutenberg is a registered trademark, and may not be used if you charge for an eBook, except by following the terms of the trademark license, including paying royalties for use of the Project Gutenberg trademark. If you do not charge anything for copies of this eBook, complying with the trademark license is very easy. You may use this eBook for nearly any purpose such as creation of derivative works, reports, performances and research. Project Gutenberg eBooks may be modified and printed and given away—you may do practically ANYTHING in the United States with eBooks not protected by U.S. copyright law. Redistribution is subject to the trademark license, especially commercial redistribution. START: FULL LICENSE
  • 40. THE FULL PROJECT GUTENBERG LICENSE
  • 41. PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK To protect the Project Gutenberg™ mission of promoting the free distribution of electronic works, by using or distributing this work (or any other work associated in any way with the phrase “Project Gutenberg”), you agree to comply with all the terms of the Full Project Gutenberg™ License available with this file or online at www.gutenberg.org/license. Section 1. General Terms of Use and Redistributing Project Gutenberg™ electronic works 1.A. By reading or using any part of this Project Gutenberg™ electronic work, you indicate that you have read, understand, agree to and accept all the terms of this license and intellectual property (trademark/copyright) agreement. If you do not agree to abide by all the terms of this agreement, you must cease using and return or destroy all copies of Project Gutenberg™ electronic works in your possession. If you paid a fee for obtaining a copy of or access to a Project Gutenberg™ electronic work and you do not agree to be bound by the terms of this agreement, you may obtain a refund from the person or entity to whom you paid the fee as set forth in paragraph 1.E.8. 1.B. “Project Gutenberg” is a registered trademark. It may only be used on or associated in any way with an electronic work by people who agree to be bound by the terms of this agreement. There are a few things that you can do with most Project Gutenberg™ electronic works even without complying with the full terms of this agreement. See paragraph 1.C below. There are a lot of things you can do with Project Gutenberg™ electronic works if you follow the terms of this agreement and help preserve free future access to Project Gutenberg™ electronic works. See paragraph 1.E below.
  • 42. 1.C. The Project Gutenberg Literary Archive Foundation (“the Foundation” or PGLAF), owns a compilation copyright in the collection of Project Gutenberg™ electronic works. Nearly all the individual works in the collection are in the public domain in the United States. If an individual work is unprotected by copyright law in the United States and you are located in the United States, we do not claim a right to prevent you from copying, distributing, performing, displaying or creating derivative works based on the work as long as all references to Project Gutenberg are removed. Of course, we hope that you will support the Project Gutenberg™ mission of promoting free access to electronic works by freely sharing Project Gutenberg™ works in compliance with the terms of this agreement for keeping the Project Gutenberg™ name associated with the work. You can easily comply with the terms of this agreement by keeping this work in the same format with its attached full Project Gutenberg™ License when you share it without charge with others. 1.D. The copyright laws of the place where you are located also govern what you can do with this work. Copyright laws in most countries are in a constant state of change. If you are outside the United States, check the laws of your country in addition to the terms of this agreement before downloading, copying, displaying, performing, distributing or creating derivative works based on this work or any other Project Gutenberg™ work. The Foundation makes no representations concerning the copyright status of any work in any country other than the United States. 1.E. Unless you have removed all references to Project Gutenberg: 1.E.1. The following sentence, with active links to, or other immediate access to, the full Project Gutenberg™ License must appear prominently whenever any copy of a Project Gutenberg™ work (any work on which the phrase “Project Gutenberg” appears, or with which the phrase “Project Gutenberg” is associated) is accessed, displayed, performed, viewed, copied or distributed:
  • 43. This eBook is for the use of anyone anywhere in the United States and most other parts of the world at no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the terms of the Project Gutenberg License included with this eBook or online at www.gutenberg.org. If you are not located in the United States, you will have to check the laws of the country where you are located before using this eBook. 1.E.2. If an individual Project Gutenberg™ electronic work is derived from texts not protected by U.S. copyright law (does not contain a notice indicating that it is posted with permission of the copyright holder), the work can be copied and distributed to anyone in the United States without paying any fees or charges. If you are redistributing or providing access to a work with the phrase “Project Gutenberg” associated with or appearing on the work, you must comply either with the requirements of paragraphs 1.E.1 through 1.E.7 or obtain permission for the use of the work and the Project Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9. 1.E.3. If an individual Project Gutenberg™ electronic work is posted with the permission of the copyright holder, your use and distribution must comply with both paragraphs 1.E.1 through 1.E.7 and any additional terms imposed by the copyright holder. Additional terms will be linked to the Project Gutenberg™ License for all works posted with the permission of the copyright holder found at the beginning of this work. 1.E.4. Do not unlink or detach or remove the full Project Gutenberg™ License terms from this work, or any files containing a part of this work or any other work associated with Project Gutenberg™. 1.E.5. Do not copy, display, perform, distribute or redistribute this electronic work, or any part of this electronic work, without prominently displaying the sentence set forth in paragraph 1.E.1 with
  • 44. active links or immediate access to the full terms of the Project Gutenberg™ License. 1.E.6. You may convert to and distribute this work in any binary, compressed, marked up, nonproprietary or proprietary form, including any word processing or hypertext form. However, if you provide access to or distribute copies of a Project Gutenberg™ work in a format other than “Plain Vanilla ASCII” or other format used in the official version posted on the official Project Gutenberg™ website (www.gutenberg.org), you must, at no additional cost, fee or expense to the user, provide a copy, a means of exporting a copy, or a means of obtaining a copy upon request, of the work in its original “Plain Vanilla ASCII” or other form. Any alternate format must include the full Project Gutenberg™ License as specified in paragraph 1.E.1. 1.E.7. Do not charge a fee for access to, viewing, displaying, performing, copying or distributing any Project Gutenberg™ works unless you comply with paragraph 1.E.8 or 1.E.9. 1.E.8. You may charge a reasonable fee for copies of or providing access to or distributing Project Gutenberg™ electronic works provided that: • You pay a royalty fee of 20% of the gross profits you derive from the use of Project Gutenberg™ works calculated using the method you already use to calculate your applicable taxes. The fee is owed to the owner of the Project Gutenberg™ trademark, but he has agreed to donate royalties under this paragraph to the Project Gutenberg Literary Archive Foundation. Royalty payments must be paid within 60 days following each date on which you prepare (or are legally required to prepare) your periodic tax returns. Royalty payments should be clearly marked as such and sent to the Project Gutenberg Literary Archive Foundation at the address specified in Section 4, “Information about donations to the Project Gutenberg Literary Archive Foundation.”
  • 45. • You provide a full refund of any money paid by a user who notifies you in writing (or by e-mail) within 30 days of receipt that s/he does not agree to the terms of the full Project Gutenberg™ License. You must require such a user to return or destroy all copies of the works possessed in a physical medium and discontinue all use of and all access to other copies of Project Gutenberg™ works. • You provide, in accordance with paragraph 1.F.3, a full refund of any money paid for a work or a replacement copy, if a defect in the electronic work is discovered and reported to you within 90 days of receipt of the work. • You comply with all other terms of this agreement for free distribution of Project Gutenberg™ works. 1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™ electronic work or group of works on different terms than are set forth in this agreement, you must obtain permission in writing from the Project Gutenberg Literary Archive Foundation, the manager of the Project Gutenberg™ trademark. Contact the Foundation as set forth in Section 3 below. 1.F. 1.F.1. Project Gutenberg volunteers and employees expend considerable effort to identify, do copyright research on, transcribe and proofread works not protected by U.S. copyright law in creating the Project Gutenberg™ collection. Despite these efforts, Project Gutenberg™ electronic works, and the medium on which they may be stored, may contain “Defects,” such as, but not limited to, incomplete, inaccurate or corrupt data, transcription errors, a copyright or other intellectual property infringement, a defective or damaged disk or other medium, a computer virus, or computer codes that damage or cannot be read by your equipment.
  • 46. 1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for the “Right of Replacement or Refund” described in paragraph 1.F.3, the Project Gutenberg Literary Archive Foundation, the owner of the Project Gutenberg™ trademark, and any other party distributing a Project Gutenberg™ electronic work under this agreement, disclaim all liability to you for damages, costs and expenses, including legal fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE. 1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you discover a defect in this electronic work within 90 days of receiving it, you can receive a refund of the money (if any) you paid for it by sending a written explanation to the person you received the work from. If you received the work on a physical medium, you must return the medium with your written explanation. The person or entity that provided you with the defective work may elect to provide a replacement copy in lieu of a refund. If you received the work electronically, the person or entity providing it to you may choose to give you a second opportunity to receive the work electronically in lieu of a refund. If the second copy is also defective, you may demand a refund in writing without further opportunities to fix the problem. 1.F.4. Except for the limited right of replacement or refund set forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
  • 47. 1.F.5. Some states do not allow disclaimers of certain implied warranties or the exclusion or limitation of certain types of damages. If any disclaimer or limitation set forth in this agreement violates the law of the state applicable to this agreement, the agreement shall be interpreted to make the maximum disclaimer or limitation permitted by the applicable state law. The invalidity or unenforceability of any provision of this agreement shall not void the remaining provisions. 1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation, the trademark owner, any agent or employee of the Foundation, anyone providing copies of Project Gutenberg™ electronic works in accordance with this agreement, and any volunteers associated with the production, promotion and distribution of Project Gutenberg™ electronic works, harmless from all liability, costs and expenses, including legal fees, that arise directly or indirectly from any of the following which you do or cause to occur: (a) distribution of this or any Project Gutenberg™ work, (b) alteration, modification, or additions or deletions to any Project Gutenberg™ work, and (c) any Defect you cause. Section 2. Information about the Mission of Project Gutenberg™ Project Gutenberg™ is synonymous with the free distribution of electronic works in formats readable by the widest variety of computers including obsolete, old, middle-aged and new computers. It exists because of the efforts of hundreds of volunteers and donations from people in all walks of life. Volunteers and financial support to provide volunteers with the assistance they need are critical to reaching Project Gutenberg™’s goals and ensuring that the Project Gutenberg™ collection will remain freely available for generations to come. In 2001, the Project Gutenberg Literary Archive Foundation was created to provide a secure and permanent future for Project Gutenberg™ and future
  • 48. generations. To learn more about the Project Gutenberg Literary Archive Foundation and how your efforts and donations can help, see Sections 3 and 4 and the Foundation information page at www.gutenberg.org. Section 3. Information about the Project Gutenberg Literary Archive Foundation The Project Gutenberg Literary Archive Foundation is a non-profit 501(c)(3) educational corporation organized under the laws of the state of Mississippi and granted tax exempt status by the Internal Revenue Service. The Foundation’s EIN or federal tax identification number is 64-6221541. Contributions to the Project Gutenberg Literary Archive Foundation are tax deductible to the full extent permitted by U.S. federal laws and your state’s laws. The Foundation’s business office is located at 809 North 1500 West, Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up to date contact information can be found at the Foundation’s website and official page at www.gutenberg.org/contact Section 4. Information about Donations to the Project Gutenberg Literary Archive Foundation Project Gutenberg™ depends upon and cannot survive without widespread public support and donations to carry out its mission of increasing the number of public domain and licensed works that can be freely distributed in machine-readable form accessible by the widest array of equipment including outdated equipment. Many small donations ($1 to $5,000) are particularly important to maintaining tax exempt status with the IRS.
  • 49. The Foundation is committed to complying with the laws regulating charities and charitable donations in all 50 states of the United States. Compliance requirements are not uniform and it takes a considerable effort, much paperwork and many fees to meet and keep up with these requirements. We do not solicit donations in locations where we have not received written confirmation of compliance. To SEND DONATIONS or determine the status of compliance for any particular state visit www.gutenberg.org/donate. While we cannot and do not solicit contributions from states where we have not met the solicitation requirements, we know of no prohibition against accepting unsolicited donations from donors in such states who approach us with offers to donate. International donations are gratefully accepted, but we cannot make any statements concerning tax treatment of donations received from outside the United States. U.S. laws alone swamp our small staff. Please check the Project Gutenberg web pages for current donation methods and addresses. Donations are accepted in a number of other ways including checks, online payments and credit card donations. To donate, please visit: www.gutenberg.org/donate. Section 5. General Information About Project Gutenberg™ electronic works Professor Michael S. Hart was the originator of the Project Gutenberg™ concept of a library of electronic works that could be freely shared with anyone. For forty years, he produced and distributed Project Gutenberg™ eBooks with only a loose network of volunteer support. Project Gutenberg™ eBooks are often created from several printed editions, all of which are confirmed as not protected by copyright in the U.S. unless a copyright notice is included. Thus, we do not
  • 50. necessarily keep eBooks in compliance with any particular paper edition. Most people start at our website which has the main PG search facility: www.gutenberg.org. This website includes information about Project Gutenberg™, including how to make donations to the Project Gutenberg Literary Archive Foundation, how to help produce our new eBooks, and how to subscribe to our email newsletter to hear about new eBooks.