ПРО СВИФТ

PRO SWIFT

Пол Хадсон (Paul Hudson)

PRO SWIFT

BOOK AND VIDEOS

Break out of beginner’s Swift with this hands-on guide

Paul HudsonPro Swift

Paul Hudson

Version: 20190526Contents

Preface 5

Welcome

Chapter 1: Syntax 10

Pattern matching

Nil coalescing

Guard

Lazy loading

Destructuring

Labeled statements

Nested functions, classes and structs

Documentation markup

Chapter 2: Types 69

Useful initializers

Enums

Arrays

Dictionaries

Sets

Tuples

Generics

Chapter 3: References and Values What’s the difference?

Closures are references

Why use structs?

Why use classes?

Choosing between structs and classes

Mixing classes and structs

Immutability

111

Chapter 4: Functions 131

Variadic functions

Operator overloading

Closures

The ~= operator

Chapter 5: Errors 160

Error fundamentals

Error propagation

Throwing functions as parameters try vs try? vs try!

Assertions

Never and fatalError()

Chapter 6: Functional programming 184

What is functional programming?

map() compactMap() flatMap() filter() reduce() sort()

Function composition

Lazy functions

Functors and monads

Chapter 7: Patterns 225

Object-oriented programming

Protocol-oriented programming

MVC

MVVM

Command-line Swift

Preface

Andy Matuschak (@andy_matuschak), lead mobile developer at Khan Academy

If you’re transforming a collection, but you don’t need to access all the elements right away (or at all), you may be able to save cycles and allocations by using the lazy family of collection types:

let userCellsData = users.lazy.map { user in

UserCellData(username: user.username, bioAttributedString:

formatBioString(user.bio))

}

Welcome

This is not a book for people who are new to Swift. I realize that’s obvious given that the book is called Pro Swift, but I want to make sure we’re getting off on the right foot. Instead, this is a book for people who have some real-world knowledge of the language – perhaps you’ve made some apps yourself, perhaps you’ve read through Apple’s official Swift reference guide, or perhaps you even read my first book, Hacking with Swift.

It is not required that you have read Hacking with Swift in order to make the most of this book, but I have to admit it certainly helps. At the very least you should have read the introduction chapter, which goes through the basics of Swift in about an hour of coding. If you haven’t already read that chapter, I suggest you pause here then go and read it at https://