Swift is a powerful and intuitive general-purpose programming language for the OS X, iOS, watchOS, and Linux operating systems. It’s developed by Apple Inc. Swift is intended to be more resilient to erroneous code (“safer”) than Objective-C, and more concise.
Swift is a new language, first appearing in 2014. It’s friendly to new programmers, feels familiar to Objective-C developers, and the language is optimized for development. It was launched under a proprietary license, but Apple made the language open source in December 2015 by releasing Swift 2.2 and later under the Apache License 2.0. By open-sourcing Swift, developers are able to use the language for their own purposes and go beyond OS X, iOS and watchOS apps.
Besides the official Swift Programming Language book (featured below), there are no other good quality open source Swift books. Given the short passage of time since Apple open sourced the language, this isn’t that surprising. There was an interesting ‘The Swift Book’, which is available under the MIT license, but it is mostly incomplete and updates have stalled. Fortunately, there are some excellent Swift books which can be read without charge which fill the void.
As at August 2019, Swift ranks 18th on the TIOBE Programming Community index, an indicator of the popularity of programming languages.
The focus of this article is to select the finest free Swift books which help programmers master this language, and develop an in-depth understanding of the benefits that this programming language offers. Each book is available to download without payment. Some of the books are available to purchase too.
1. The Swift Programming Language by Apple Inc.
The Swift Programming Language is the authoritative reference for Swift, offering a guided tour, a comprehensive guide, and a formal reference of the language.
The book is available as a ePub, but there are PDF versions available to download.
This book is made available under the Creative Commons Attribution 4.0 International (CC BY 4.0) License. Unfortunately, the rest of the books featured in this article are not released under an open source license.
2. Hacking with Swift by Paul Hudson
Hacking with Swift is designed for beginners to intermediate programmers wishing to learn Swift 3 and iOS development with real-world, practical projects. The e-book contains the following projects.
- Storm Viewer: Get started coding in Swift by making an image viewer app and learning key concepts.
- Guess the Flag: Make a game using UIKit, and learn about integers, buttons, colors and actions.
- Social Media: Let users share to Facebook and Twitter by modifying project 1.
- Easy Browser: Embed Web Kit and learn about delegation, KVO, classes and UIToolbar.
- Word Scramble: Create an anagram game while learning about closures and booleans.
- Auto Layout: Get to grips with Auto Layout using practical examples and code.
- Whitehouse Petitions: Make an app to parse Whitehouse petitions using JSON and a tab bar.
- 7 Swifty Words: Build a word-guessing game and master strings once and for all.
- Grand Central Dispatch: Learn how to run complex tasks in the background with GCD.
- Names to Faces: Get started with UICollectionView and the photo library.
- Pachinko: Dive into SpriteKit to try your hand at fast 2D games.
- UserDefaults: Learn how to save user settings and data for later use.
- Instafilter: Make a photo manipulation program using Core Image filters and a UISlider.
- Whack-a-Penguin: Build a game using SKCropNode and a sprinkling of Grand Central Dispatch.
- Animation: Bring your interfaces to life with animation, and meet switch/case at the same time.
- JavaScript Injection: Extend Safari with a cool feature for JavaScript developers.
- Swifty Ninja: Learn to draw shapes in SpriteKit while making a fun and tense slicing game.
- Debugging: Everyone hits problems sooner or later, so learning to find and fix them is an important skill.
- Capital Cities: Teach users about geography while you learn about MKMapView and annotations.
- Fireworks Night: Learn about timers and color blends while making things go bang!
- Local Notifications: Send reminders, prompts and alerts even when your app isn’t running.
- Detect-a-Beacon: Learn to find and range iBeacons using our first project for a physical device.
- Space Race: Dodge space debris while you learn about per-pixel collision detection.
- Swift Extensions: Try your hand at improving the built-in data types of Swift.
- Selfie Share: Make a multi-peer photo sharing app in just 150 lines of code.
- Marble Maze: Respond to device tilting by steering a ball around a vortex maze.
- Core Graphics: Draw 2D shapes using Apple’s high-speed drawing framework.
- Secret Swift: Save user data securely using the device keychain and Touch ID.
- Exploding Monkeys: Remake a classic DOS game and learn about destructible terrain and scene transitions.
- Instruments: Become a bug detective and track down lost memory, slow drawing and more.
- Multibrowser: Get started with UIStackView and see just how easy iPad multitasking is.
- SwiftSearcher: Add your app’s content to Spotlight search and take advantage of the new Safari integration.
- What’s that Whistle?: Build a crowd-sourced song recognition app using Apple’s free platform as a service. CloudKit.
- Four in a Row: Let iOS take over the AI in your games using GameplayKit.
- Generating random numbers: GameplayKit can help you generate random numbers in ways you soon won’t be able to live without.
- Crashy Plane: Ever wanted to make a Flappy Bird clone? Now you can do it in under an hour thanks to SpriteKit.
- Psychic Tester: Are you psychic? Of course not. But what if we could use our coding skills to make a game to fool your friends into thinking otherwise?
- GitHub Commits: Get on board with Core Data and learn to read, write and query objects using Apple’s object graph and persistence framework.
- Unit testing with XCTest: Learn how to write unit tests and user interface tests using Xcode’s built-in testing framework.
This book is not released under an open source license.
3. Learn Swift by Aidan Finn
Swift is a wonderful language that gives you an easy entry-point into the Apple developer ecosystem. If you’ve been put off developing for OS X and iOS because of the need to learn Objective-C, now is the time to start.
Swift offers a relatively smooth transition from languages like Ruby and Python. This short book offers you a whirlwind tour of Swift. The aim of this book is to quickly and succinctly introduce and demonstrate all the major features of the Swift programming language.
Chapters cover:
- Running Code – create a simple hello world program and run it in Swift.
- Basics – sets out some of the basics of Swift.
- Constants and Variables.
- Static Typing and Type Inference – with reference to the benefits of static typing.
- Arrays.
- Dictionaries – learn how to perform some common operations on dictionaries.
- Tuples – a brief look at this ordered list of elements.
- Control Flow – if, loops, switch, altering control.
- Optionals – declaring, forced unwrapping, conditional unwrapping, using optionals, and dictionaries.
- Functions and Closures – defining and more.
- Classes – introduces classes, showing you how to define a class, methods, properties: stored and computed, lazy stored properties, property callbacks, subscripts, object initialization, deinitialization, inheritance, and more.
- Structures – highlights the differences between structures and classes.
- Enumerations – defining and using, raw values, associated values, associates values versus raw values, pattern matching with switch.
- Protocols – defining and conforming to a protocol.
- Extensions – defining extensions.
- Memory Management – highlights where you may need to get involved in the memory management of objects manually.
- Error handling – try, catch and throws, assertions, enums.
- Generics – a way of defining functions or types that can work with multiple different data types.
- What next? – some resources for building iOS or OS X apps in Swift.
All books in this series:
Free Programming Books | |
---|---|
Java | General-purpose, concurrent, class-based, object-oriented, high-level language |
C | General-purpose, procedural, portable, high-level language |
Python | General-purpose, structured, powerful language |
C++ | General-purpose, portable, free-form, multi-paradigm language |
C# | Combines the power and flexibility of C++ with the simplicity of Visual Basic |
JavaScript | Interpreted, prototype-based, scripting language |
PHP | PHP has been at the helm of the web for many years |
HTML | HyperText Markup Language |
SQL | Access and manipulate data held in a relational database management system |
Ruby | General purpose, scripting, structured, flexible, fully object-oriented language |
Assembly | As close to writing machine code without writing in pure hexadecimal |
Swift | Powerful and intuitive general-purpose programming language |
Groovy | Powerful, optionally typed and dynamic language |
Go | Compiled, statically typed programming language |
Pascal | Imperative and procedural language designed in the late 1960s |
Perl | High-level, general-purpose, interpreted, scripting, dynamic language |
R | De facto standard among statisticians and data analysts |
COBOL | Common Business-Oriented Language |
Scala | Modern, object-functional, multi-paradigm, Java-based language |
Fortran | The first high-level language, using the first compiler |
Scratch | Visual programming language designed for 8-16 year-old children |
Lua | Designed as an embeddable scripting language |
Logo | Dialect of Lisp that features interactivity, modularity, extensibility |
Rust | Ideal for systems, embedded, and other performance critical code |
Lisp | Unique features - excellent to study programming constructs |
Ada | ALGOL-like programming language, extended from Pascal and other languages |
Haskell | Standardized, general-purpose, polymorphically, statically typed language |
Scheme | A general-purpose, functional language descended from Lisp and Algol |
Prolog | A general purpose, declarative, logic programming language |
Forth | Imperative stack-based programming language |
Clojure | Dialect of the Lisp programming language |
Julia | High-level, high-performance language for technical computing |
Awk | Versatile language designed for pattern scanning and processing language |
CoffeeScript | Transcompiles into JavaScript inspired by Ruby, Python and Haskell |
BASIC | Beginner’s All-purpose Symbolic Instruction Code |
Erlang | General-purpose, concurrent, declarative, functional language |
VimL | Powerful scripting language of the Vim editor |
OCaml | The main implementation of the Caml language |
ECMAScript | Best known as the language embedded in web browsers |
Bash | Shell and command language; popular both as a shell and a scripting language |
LaTeX | Professional document preparation system and document markup language |
TeX | Markup and programming language - create professional quality typeset text |
Arduino | Inexpensive, flexible, open source microcontroller platform |
TypeScript | Strict syntactical superset of JavaScript adding optional static typing |
Elixir | Relatively new functional language running on the Erlang virtual machine |
F# | Uses functional, imperative, and object-oriented programming methods |
Tcl | Dynamic language based on concepts of Lisp, C, and Unix shells |
Factor | Dynamic stack-based programming language |
Eiffel | Object-oriented language designed by Bertrand Meyer |
Agda | Dependently typed functional language based on intuitionistic Type Theory |
Icon | Wide variety of features for processing and presenting symbolic data |
XML | Rules for defining semantic tags describing structure ad meaning |
Vala | Object-oriented language, syntactically similar to C# |
Standard ML | General-purpose functional language characterized as "Lisp with types" |
D | General-purpose systems programming language with a C-like syntax |
Dart | Client-optimized language for fast apps on multiple platforms |
Markdown | Plain text formatting syntax designed to be easy-to-read and easy-to-write |
Kotlin | More modern version of Java |
Objective-C | Object-oriented language that adds Smalltalk-style messaging to C |
PureScript | Small strongly, statically typed language compiling to JavaScript |
ClojureScript | Compiler for Clojure that targets JavaScript |
VHDL | Hardware description language used in electronic design automation |