Beginning programming with Swift! This book takes you from beginner to advanced in Swift: Apple’s modern programming language for iOS.
This is a book for complete beginners to Apple’s new, modern programming language — Swift.
All the code in the book works inside of Xcode’s easy-to-use playgrounds. That means you can focus on core Swift language concepts, such as classes, protocols, and generics, instead of getting bogged down in the details of building apps.
This is a companion book to the iOS Apprentice; the iOS Apprentice focuses on building apps, while Swift Apprentice focuses on the Swift language itself.
First, you’ll learn how computers and programming languages work, then lead into playgrounds, which you’ll use to run the code in this book. See how simple expressions, variables and constants work in Swift, then move on to how Swift handles types and operations. Learn more language fundamentals involving control flow, making decisions with conditionals and repeating things with loops. You’ll also learn to group procedures into functions, and how to use optionals to guard against cases where there may or may not be a value to work with.
This is it, your whirlwind introduction to the world of programming! You’ll begin with an overview of computers and programming, and then say hello to Swift playgrounds, which are where you’ll spend your coding time for the rest of this book. You’ll learn some basics such as code comments, arithmetic operations, constants and variables. These are some of the fundamental building blocks of any language, and Swift is no different.
You’ll learn about handling different types, including strings which allow you to represent text. You’ll learn about converting between types and you’ll also be introduced to type inference which makes your life as a programmer a lot simpler. You’ll learn about tuples which allow you to make your own types made up of multiple values of any type.
You’ll learn how to make decisions and repeat tasks in your programs by using syntax to control the flow. You’ll also learn about Booleans, which represent true and false values, and how you can use these to compare data.
Continuing the theme of code not running in a straight line, you’ll learn about another loop known as the `for` loop. You’ll also learn about switch statements which are particularly powerful in Swift.
Functions are the basic building blocks you use to structure your code in Swift. You’ll learn how to define functions to group your code into reusable units.
This chapter covers optionals, a special type in Swift that represents either a real value or the absence of a value. By the end of this chapter, you’ll know why you need optionals and how to use them safely.
Why have one thing when you can have many? Learn about the various collection types available to you in Swift, and how to work with your collections through closures.
Arrays are the most common collection type you’ll run into in Swift. Arrays are typed, as are regular variables and constants and store multiple values like a single list.
Swift has an object you can use to break up code into reusable chunks: a closure. These are particularly important when dealing with collections.
Finally, you will revisit strings, which are actually bi-directional collections of unicode characters.
With the basics of Swift programming and collections under your belt, you can turn your attention to compound types in Swift. You’ll combine code and data into structures and classes, work with properties, learn how methods are different from functions, get started with classes, enumerate through collections, see how to implement protocols and learn how generics can help you out.
This chapter introduces structures, which are the first named type you’ll learn about. Structures are types that can store named properties and define their own behaviors.
In this chapter, you’ll learn about stored and computed properties, along with some tricks to deal with properties, how to monitor changes in a property’s value and delay initialization of a stored property.
Methods are merely functions that reside in a structure. In this chapter, you’ll take a closer look at methods and initializers.
Structures introduced you to your first named type, which lets you define your own named types. In this chapter, you’ll get acquainted with classes, which are much like structures.
This chapter introduces the finer points of classes and helps you understand how you can create, use and manage complex classes.
In this chapter, you’ll learn how enumerations work and when they’re useful. As a bonus, you’ll finally discover what an optional is under the hood.
Protocols are a type that can bridge common behaviors between structs, classes, and enums by defining an interface or template for an actual concrete type.
In this chapter, you’ll learn what generics are, learn how to write your own generic code, and loop back and look at the generic types in Swift - dictionaries, arrays, and optionals - from this new perspective.
Become a Swift master with advanced language features! Learn how to keep your code organized with public and private declarations, see how extensions work, and create your own custom operators and subscripts. Learn how to keep your code simple with pattern matching, manage real-world gotchas with error handling, discover the difference between value and reference types, and see how asynchronous closures and ARC work together to manage memory and avoid memory leaks. Finally, learn why Swift is referred to as a “protocol-oriented” language and how to extend protocols yourself.
Swift gives you powerful tools for hiding complexity and organizing your code into easier to digest units. This chapter details how to do that.
You’ll learn how you can define your own operators and subscripts to make your types feel even more like built-in language constructs.
With pattern matching you can accomplish more — with less typing. You’ll master all of its many forms in this chapter.
In the real world, some errors cannot be avoided. Handling them gracefully is what sets apart mediocre code from great code.
You will learn about the type serialization system introduced in Swift 4 with particular emphasis on the JSON format.
This chapter digs into the details of Swift memory management examining the relation between objects. It shows you how you avoid common leaks.
Value semantics have a clear advantage over reference semantics in terms of the local reasoning but can lead to inefficiency for large objects. This chapter shows you how to get the best of both worlds.
From the standard library to user authored generics, Swift is a protocol-based language. In this chapter you’ll see how to get all of the benefits associated with object-oriented programming while being able to avoid most of the difficulties.
Learn how to use constraints to make generic code more useful and how to hide implementation details with opaque return types.
Clear tuition without guesswork or confusion. Concepts that are easy to absorb.Rob W.
Apple's documentation is great, but it lacks the gentle approach of this book. I always have the PDF open for quick lookups!Blaise B.
As a novice developer trying to learn Swift, this series was exactly what I needed to get started. It shows you how to build actual applications that teach you many of the fundamentals of Swift.Seth M.