An Introduction to Programming Using Swift

Around the days of Swift 2 (over 10 years ago), I started working on a textbook teaching programming using Swift. As Swift 3 and 4 came along, I had the privilege of going back and rewriting the book as the language changed so much the old text was unusable. I sat the project aside for the day when Swift would stabilize enough so that I didn't have to redo everything when a new release appeared.

Swift 6.0 came along, and I had thought that day arrived; so I began work on the project again. Sadly, a few changes I discovered in Swift force me to go through the entire book again. Nevertheless, it has reached a point where I can put out a beta release of the book.

An Introduction to Programming Using Swift is 2,600+ pages long (PDF format). This includes 25 chapters plus 12 appendices. The beta 0.5.1 release includes proof-read versions of chapters 1-17 with the remaining chapters still in rough draft form. I'm putting this out in beta form to get feedback (particularly on the first 17 chapters, which cover the majority of the language that newcomers to Swift will want to learn).

The full scoop on the book can be found here:
https://introtoswift.randallhyde.com
You can get the beta version here:
gum road

The book is available in three formats:
PDF,
EPUB3 (Apple Books)
AZW3 (Kindle Paperwhite)

I have tried to format the output so that it is (mostly) readable on a Paperwhite, but PDF is the best format and EPUB3 is decent (AZW3 is least desirable, as the Kindle doesn't do a good job rendering EPUB).

FYI, here's the short version of the TOC (full TOC is available at introtoswift....):

An Introduction to Programming Using Swift

Brief Table of Contents

0 Preface to the Beta Edition............................................................ lx

I Introduction...................................................................................... 1

1 An Introduction to Programming Using Swift............................ 13

2 An Introduction to Computing..................................................... 63

3 An Introduction to Software Engineering................................. 103

4 Basic Data Types and Statements in Swift............................... 165

5 Decisions..................................................................................... 247

6 Repetition and Loops.................................................................. 335

7 Program Units: Functions and Closures.................................. 389

8 Top-Down Design........................................................................ 513

9 Error Handling............................................................................. 545

10 Sequences, Collections, and Ranges...................................... 579

11 Arrays......................................................................................... 611

12 Sets and Dictionaries................................................................ 687

13 Characters, Character Sets, and Strings................................ 733

14 Enumerations............................................................................ 815

15 Tuples and Structures.............................................................. 903

16 Classes....................................................................................... 991

17 Protocols, Extensions, and Generics.................................... 1157

18 Object-Oriented Programming.............................................. 1317

19 Design Patterns....................................................................... 1391

20 Protocol-Oriented Programming........................................... 1619

21 File I/O...................................................................................... 1683

22 Modular Programming in Swift.............................................. 1753

23 Dates, Times, and Measurements.......................................... 1803

24 Regular Expressions............................................................... 1865

25 Where to go From Here........................................................... 1953

A Glossary.................................................................................... 1967

B Installing Swift on Your System.............................................. 1977

C Answers to the Exercises........................................................ 1985

D Designs...................................................................................... 2015

E Standard Library Mathematical Functions............................. 2157

F Sequence and Collection Methods.......................................... 2163

G Array Reference........................................................................ 2213

H The CPU’s Hardware Stack...................................................... 2261

I Set Reference............................................................................. 2271

J Dictionary Reference................................................................ 2305

K String and CharacterSet Reference........................................ 2335

L Standard Library Protocols (Reference)................................. 2487

M The String Pattern Matching Library...................................... 2505

Index........................................................................................... 2553

I'll leave the beta version open (along with updates, as things improve) until the first edition release of the book. So participating in the beta is a good way to get this book cheap ($5).
Feedback is welcome at https://randallhyde.com/Forum/index.php (please check the registration sub-forum before trying to sign up).

Thanks for your kind consideration.

P.S. Someday, when I can navigate through the problems I'm having, I'll get the EPUB3 version up on Apple Books, too.

8 Likes

I got the book to start reading it some. I checked out appendix B and looks like the Windows installation instructions are very outdated- we actually have some official tool chains from Swift.org now:

Also for Raspberry Pi the swift-arm project is now “dead” and official tool chains are available for aarch64 as well. Swiftly can also be used, so I’d even recommend adding a section in using that for macOS, Linux, and the Pi!

5 Likes

I would like to have nice chapter about Actors and all async stuff.

1 Like

As this is an "Introductory" text, I've largely avoided getting into concurrency. If I get through this project, I would consider a volume 2 that would cover topics such as:

  1. Unsafe...
  2. Swift syntax
  3. Macros
  4. Concurrency
  5. Interfacing with other languages (esp. C/C++ and assembly)

I would really have liked to include a chapter on Test-Directed Development (TDD) and testing in general. However, to do such a chapter properly requires too much platform-specific work, so I put that off. That might also be a good extension in a volume 2.

1 Like

FWIW, I tried installing the Swift Extensions from Windows (running under Parallels on an x86 mac). It kept trying to install the code on macOS. Am I missing something here?

My current plan is to update one "main" chapter and one "appendix" with each beta release. So the next release will cover CH 18 and Appendix A. The second release will include CH 19 and Appendix B. I'll try and get all the Windows/Pi stuff updated by Beta 0.5.3.

FWIW, I finally cleaned up the EPUB3 version so Apple Books would accept it:

Fair amount of example text available there (including the full appendix) if you'd like to peruse it first.

1 Like