Swift in Depth

Book description

Swift in Depth guides you concept by concept through the skills you need to build professional software for Apple platforms, such as iOS and Mac; also on the server with Linux. By following the numerous concrete examples, enlightening explanations, and engaging exercises, you’ll finally grok powerful techniques like generics, efficient error handling, protocol-oriented programming, and advanced Swift patterns. Author Tjeerd in ’t Veen reveals the high-value, difficult-to-discover Swift techniques he’s learned through his own hard-won experience.

Table of contents

  1. Copyright
  2. Brief Table of Contents
  3. Table of Contents
  4. Preface
  5. Acknowledgements
  6. About this Book
    1. Why this book?
    2. Is this book for you?
    3. What this book is not
    4. A big emphasis on practical scenarios
    5. Roadmap
    6. About the code
    7. Book forum
    8. About the author
    9. About the cover illustration
  7. Chapter 1. Introducing Swift in depth
    1. 1.1. The sweet spot of Swift
    2. 1.2. Below the surface
    3. 1.3. Swift’s downsides
    4. 1.4. What you will learn in this book
    5. 1.5. How to make the most of this book
    6. 1.6. Minimum qualifications
    7. 1.7. Swift version
    8. Summary
  8. Chapter 2. Modeling data with enums
    1. 2.1. Or vs. and
    2. 2.2. Enums for polymorphism
    3. 2.3. Enums instead of subclassing
    4. 2.4. Algebraic data types
    5. 2.5. A safer use of strings
    6. 2.6. Closing thoughts
    7. Summary
    8. Answers
  9. Chapter 3. Writing cleaner properties
    1. 3.1. Computed properties
    2. 3.2. Lazy properties
    3. 3.3. Property observers
    4. 3.4. Closing thoughts
    5. Summary
    6. Answers
  10. Chapter 4. Making optionals second nature
    1. 4.1. The purpose of optionals
    2. 4.2. Clean optional unwrapping
    3. 4.3. Variable shadowing
    4. 4.4. When optionals are prohibited
    5. 4.5. Returning optional strings
    6. 4.6. Granular control over optionals
    7. 4.7. Falling back when an optional is nil
    8. 4.8. Simplifying optional enums
    9. 4.9. Chaining optionals
    10. 4.10. Constraining optional Booleans
    11. 4.11. Force unwrapping guidelines
    12. 4.12. Taming implicitly unwrapped optionals
    13. 4.13. Closing thoughts
    14. Summary
    15. Answers
  11. Chapter 5. Demystifying initializers
    1. 5.1. Struct initializer rules
    2. 5.2. Initializers and subclassing
    3. 5.3. Minimizing class initializers
    4. 5.4. Required initializers
    5. 5.5. Closing thoughts
    6. Summary
    7. Answers
  12. Chapter 6. Effortless error handling
    1. 6.1. Errors in Swift
    2. 6.2. Error propagation and catching
    3. 6.3. Delivering pleasant APIs
    4. 6.4. Closing thoughts
    5. Summary
    6. Answers
  13. Chapter 7. Generics
    1. 7.1. The benefits of generics
    2. 7.2. Constraining generics
    3. 7.3. Multiple constraints
    4. 7.4. Creating a generic type
    5. 7.5. Generics and subtypes
    6. 7.6. Closing thoughts
    7. Summary
    8. Answers
  14. Chapter 8. Putting the pro in protocol-oriented programming
    1. 8.1. Runtime versus compile time
    2. 8.2. The why of associated types
    3. 8.3. Passing protocols with associated types
    4. 8.4. Closing thoughts
    5. Summary
    6. Answers
  15. Chapter 9. Iterators, sequences, and collections
    1. 9.1. Iterating
    2. 9.2. The powers of Sequence
    3. 9.3. Creating a generic data structure with Sequence
    4. 9.4. The Collection protocol
    5. 9.5. Creating a collection
    6. 9.6. Closing thoughts
    7. Summary
    8. Answers
  16. Chapter 10. Understanding map, flatMap, and compactMap
    1. 10.1. Becoming familiar with map
    2. 10.2. Mapping over sequences
    3. 10.3. Mapping over optionals
    4. 10.4. map is an abstraction
    5. 10.5. Grokking flatMap
    6. 10.6. flatMapping over collections
    7. 10.7. Closing thoughts
    8. Summary
    9. Answers
  17. Chapter 11. Asynchronous error handling with Result
    1. 11.1. Why use the Result type?
    2. 11.2. Propagating Result
    3. 11.3. Transforming values inside Result
    4. 11.4. Handling multiple errors with Result
    5. 11.5. Error recovery with Result
    6. 11.6. Impossible failure and Result
    7. 11.7. Closing thoughts
    8. Summary
    9. Answers
  18. Chapter 12. Protocol extensions
    1. 12.1. Class inheritance vs. Protocol inheritance
    2. 12.2. Protocol inheritance vs. Protocol composition
    3. 12.3. Overriding priorities
    4. 12.4. Extending in two directions
    5. 12.5. Extending with associated types
    6. 12.6. Extending with concrete constraints
    7. 12.7. Extending Sequence
    8. 12.8. Closing thoughts
    9. Summary
    10. Answers
  19. Chapter 13. Swift patterns
    1. 13.1. Dependency injection
    2. 13.2. Conditional conformance
    3. 13.3. Dealing with protocol shortcomings
    4. 13.4. An alternative to protocols
    5. 13.5. Closing thoughts
    6. Summary
    7. Answers
  20. Chapter 14. Delivering quality Swift code
    1. 14.1. API documentation
    2. 14.2. Comments
    3. 14.3. Settling on a style
    4. 14.4. Kill the managers
    5. 14.5. Naming abstractions
    6. 14.6. Checklist
    7. 14.7. Closing thoughts
    8. Summary
  21. Chapter 15. Where to Swift from here
    1. 15.1. Build frameworks that build on Linux
    2. 15.2. Explore the Swift Package Manager
    3. 15.3. Explore frameworks
    4. 15.4. Challenge yourself
  22. Index
  23. List of Figures
  24. List of Listings

Product information

  • Title: Swift in Depth
  • Author(s): Tjeerd in 't Veen
  • Release date: December 2018
  • Publisher(s): Manning Publications
  • ISBN: 9781617295188