Swift in Depth
Tjeerd in 't Veen
  • MEAP began September 2017
  • Publication in Summer 2018 (estimated)
  • ISBN 9781617295188
  • 475 pages (estimated)
  • printed in black & white
Swift is more than just a fun language to build iOS applications with. It features a host of powerful tools that, if you know how to effectively use them, can help create even better apps with clean, crystal-clear code and awesome features. Swift in Depth is designed to help you unlock these tools and quirks and get developing next-gen apps!
Table of Contents detailed table of contents

1. Introducing Swift in depth

1.1. Why Swift?

1.2. Why this book?

1.3. Is this book for you?

1.4. What this book is not

1.5. A big emphasis on practical scenarios

1.6. How to make the most of this book

1.7. Swift version

1.8. Chapter layout

1.8.1. Chapter 2: Modeling data with enums

1.8.2. Chapter 3: Understanding initializer gotchas

1.8.3. Chapter 4: Writing cleaner properties

1.8.4. Chapter 5: Making optionals second nature

1.8.5. Chapter 6: Being a Swifty citizen

1.8.6. Chapter 7: Writing reusable code

1.8.7. Chapter 8: Understanding map and flatMap

1.8.8. Chapter 9: Fighting the pyramid of doom

1.8.9. Chapter 10: Error handling 2.0

1.8.10. Chapter 11: Putting the pro in Protocol Oriented Programming

1.8.11. Chapter 12: Building a datastructure

1.8.12. Chapter 13: Safer Swift

1.9. Strap on your seatbelt

2. Modeling data with enums

2.1. Enums instead of subclassing

2.1.1. Forming a model for a workout app

2.1.2. Creating a superclass

2.1.3. The downsides of subclassing

2.1.4. Refactoring a data model with enums

2.1.5. Deciding on subclassing or enums

2.1.6. Exercises

2.2. Enums for polymorphism

2.2.1. Compile-time polymorphism

2.3. Or versus and

2.3.1. Modeling data with a struct

2.3.2. Turning a struct into an enum

2.4. Enums are algebraic data types

2.4.1. Algebraic data types

2.4.2. Sum types

2.4.3. Product types

2.4.4. Distributing a sum over an enum

2.4.5. Exercise

2.4.6. A safer use of strings

2.4.7. Finishing up

2.5. Summary

2.6. Answers

3. Demystifying initializers

3.1. Struct initializer rules

3.1.1. Custom initializers

3.1.2. Struct initializer quirk

3.1.3. Exercises

3.2. Class initializers

3.2.1. Creating a board game superclass

3.2.2. BoardGame’s initializers

3.2.3. Creating a subclass

3.2.4. Losing convenience initializers

3.2.5. Getting the superclass initializers back

3.2.6. Exercise

3.3. Minimizing class initializers

3.3.1. Convenience overrides

3.3.2. Subclassing a subclass

3.3.3. Exercise

3.4. Required initializers

3.4.1. Factory methods

3.4.2. Protocols

3.4.3. When classes are final

3.4.4. Exercises

3.4.5. Finishing up

3.5. Summary

3.6. Answers

4. Writing cleaner properties

4.1. Computed properties

4.1.1. Modelling an exercise

4.1.2. Converting functions to computed properties

4.1.3. Rounding up

4.1.4. Exercises

4.2. Lazy properties

4.2.1. Creating a health plan

4.2.2. When computed properties don’t cut it

4.2.3. Using lazy properties

4.2.4. Making a lazy property robust

4.2.5. Mutable properties and lazy properties

4.2.6. Exercises

4.3. Property observers

4.3.1. Trimming whitespace

4.3.2. Trigger property observers from initializers

4.3.3. Exercises

4.3.4. Answers

4.3.5. Finishing up

4.4. Summary

4.5. Answers

5. Making optionals second nature

5.1. The purpose of optionals

5.2. Clean optional unwrapping

5.2.1. Matching on optionals

5.2.2. Unwrapping techniques

5.2.3. When you’re not interested in a value

5.3. Variable shadowing

5.3.1. Implementing CustomStringConvertible

5.4. When optionals are prohibited

5.4.1. Adding a computed property

5.5. Returning empty strings

5.6. Granular control over optionals

5.6.1. Exercises

5.7. Falling back when an optional is nil

5.8. Simplifying optional enums

5.8.1. Exercise

5.9. Chaining optionals

5.10. Constraining optional booleans

5.10.1. Reducing a boolean to two states

5.10.2. Falling back on true

5.10.3. A boolean with three states

5.10.4. Implementing RawRepresentable

5.10.5. Exercise

5.11. Force unwrapping guidelines

5.11.1. When force unwrapping is "acceptable"

5.11.2. Crashing with style

5.12. Taming Implicitly Unwrapped Optionals

5.12.1. Recognizing IUO’s

5.12.2. When to create IUO’s

5.12.3. Handling retrieved IUO’s

5.12.4. Subtle behavior of IUO’s

5.12.5. Finishing up

5.13. Summary

5.14. Answers

6. Generics and higher-order functions

6.1. Higher-order functions

6.1.1. Creating a function accepting a function

6.1.2. Communicating with a nested function

6.1.3. Filter

6.1.4. Exercise

6.2. Abstracting to a higher-order function

6.2.1. The steps in creating a higher-order function

6.2.2. Exercises

6.3. Making our function generic

6.3.1. Reasoning about generics

6.3.2. Exercises

6.4. Constraining generics

6.4.1. Needing a constrained function

6.4.2. The Equatable and Comparable protocols

6.4.3. Constraining means specializing

6.4.4. Using a generic function on custom types

6.4.5. Constraining versus flexibility

6.5. Multiple constraints

6.5.1. The Hashable protocol

6.5.2. Combining constraints

6.5.3. Exercises

6.6. Creating a generic type

6.6.1. Wanting to combine two Hashable types

6.6.2. Creating a Pair type

6.6.3. Multiple generics

6.6.4. Conforming to Hashable

6.6.5. Hash collisions

6.6.6. Decoupling a hashing function

6.6.7. A general purpose hashing function

6.6.8. Exercise

6.7. Summary

6.8. Answers

7. Delivering quality Swift code

8. Understanding map and flatMap

9. Error handling 2.0

10. Putting the pro in Protocol Oriented Programming

11. Building data structures with protocols

12. Creating a maintainable project

13. Writing safe Swift code

About the Technology

Apple's Swift is the standard language for iOS and Mac development. It's is a modern marvel—easy to pick up, comfortable to use, and loaded with features. After you master the basics, there's a rich, deep world of Swift skills for delivering cleaner, faster code. This book distills the hard-won experience of seasoned Swift developer Tjeerd in 't Veen into a collection of high-value, hard-to-find techniques that will help set you and your Swift applications apart.

About the book

Swift in Depth builds on your core Swift language skills, introducing you to powerful techniques like using higher-order functions, generics, efficient error handling, and protocol-oriented programming. You'll explore each new concept through concrete examples, enlightened explanations, and engaging exercises. Some of this stuff is difficult, so you'll really appreciate the careful, crystal clear writing and precise illustrations. When you're finished, you'll be a more productive Swift developer, and a happier Swift developer, as well!

What's inside

  • Adding advanced Swift features to your code
  • Writing reusable code with generics
  • Iterators, sequences, and collections
  • Protocol oriented programming

About the reader

Readers should have some prior experience with the basics of Swift.

About the author

Tjeerd in 't Veen is a senior software engineer and architect who builds iOS apps. Having worked together with many developers, he currently helps creating clean, scalable architectures in the mobile division of a large international banking firm.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
Buy
MEAP combo $49.99 pBook + eBook + liveBook
MEAP eBook $39.99 pdf + ePub + kindle + liveBook

FREE domestic shipping on three or more pBooks