Mastering Swift 6 - Seventh Edition

Book description

Master Swift 6 using advanced techniques and modern programming practices to effortlessly build high-performance applications. Purchase of the print or Kindle book includes a free eBook in PDF format.

Key Features

  • Master the new Swift 6 features to enhance your application development
  • Learn advanced techniques like concurrency, memory management, and custom operators
  • Apply best practices in Swift to write clean, scalable, and maintainable code

Book Description

Mastering Swift 6 is your ultimate guide to harnessing the full power of Swift. Whether you're aiming to optimize the performance of your application or looking to explore the exciting new features in Swift, this book has you covered. With a strong focus on practical applications, you'll dive deep into advanced concepts and techniques, such as concurrency, memory management, and generics, all essential for creating high-performance applications.

As you progress through this book, you'll begin by exploring the latest features of Swift 6 before moving on to more advanced topics like advanced operators and error handling. Each chapter builds on the previous one, introducing best practices, testing strategies, and modern programming techniques. By the end, you’ll have a deep understanding of Swift’s complexities, equipping you with the skills to develop scalable, high-performance applications with confidence.

Whether you're looking to stay competitive or simply want to excel in Swift 6, this book provides the tools and knowledge you need to succeed.

What you will learn

  • Implement the latest Swift 6 features in your applications
  • Optimize your application's performance with advanced techniques to meet the demands of the modern user
  • Apply best practices for Swift development to write clean and maintainable code
  • Master modern programming techniques essential for today's developers
  • Conquer advanced topics like concurrency, memory management, and generics
  • Learn to use result builders and how to create custom operators in Swift
  • Learn how to effectively test your Swift code for robust applications

Who this book is for

This book is for developers who have a fundamental grasp of the Swift language and who aspire to take their development skills to the next level by learning some of the advanced topics and techniques of the Swift Language. All examples should be compatible with Linux, in addition to the MacOS, iOS, iPadOS, VisionOS, and WatchOS platforms unless otherwise noted.

Table of contents

  1. Mastering Swift 6, Seventh Edition: Build high-performance applications with ease using the latest features of Swift 6
  2. Swift
    1. Join our book community on Discord
    2. How Swift has evolved
      1. Swift was born
      2. Swift evolved
    3. What’s new with Swift 6.0?
    4. Swift.org
      1. Comprehensive documentation and guides
      2. The Swift standard library and Core Libraries
      3. The Swift Package Manager
      4. Continuous integration and source compatibility
      5. Contributing to Swift
      6. A thriving community
    5. Summary
  3. Closures and Result Builders
    1. Join our book community on Discord
    2. Introducing to Closures
    3. Simple Closures
    4. Shorthand syntax for closures
    5. Using closures with Swift arrays
    6. Advanced Closures Example
    7. Result Builders
    8. Summary
  4. Protocols and Protocol Extensions
    1. Join our book community on Discord
    2. Protocols as types
    3. Polymorphism with protocols
    4. Typecasting with protocols
    5. Protocol extensions
    6. Any and any
      1. Uppercase "Any"
      2. Existential "any" in Swift
    7. Adopting protocols using a synthesized implementation
    8. Summary
  5. Generics
    1. Join our book community on Discord
    2. Introducing generics
    3. Generic functions
      1. Defining Generic Functions
      2. Calling Generic Functions
    4. Type Constraints
    5. Generic types
      1. Conditionally adding extensions with generics
      2. Conditionally adding functions
      3. Conditional conformance
    6. Generic subscripts
    7. Associated types
    8. Implicitly Opened Existentials
    9. Summary
  6. Value and Reference Types
    1. Join our book community on Discord
    2. Value types and reference types
      1. inout parameters and value types
      2. Noncopyable Types
      3. Recursive data types for reference types
      4. Inheritance for reference types
      5. Dynamic dispatch
      6. Copy-on-write
      7. Creating a backend storage type
      8. Creating a queue type
      9. Using the queue type
    3. Summary
  7. Enumerations
    1. Join our book community on Discord
    2. Raw Values
    3. Associated Values
    4. Pattern Matching
    5. Enumeration Iteration
    6. Going Beyond Basic Values
    7. Summary
  8. Reflection
    1. Join our book community on Discord
    2. Introducing Mirror API
    3. Getting Started with the Mirror API
    4. Serializing objects
    5. Summary
  9. Error Handling and Availability
    1. Join our book community on Discord
    2. Native error handling
      1. Representing errors
      2. Throwing errors
    3. Catching errors
    4. LocalizedError Protocol
    5. Defer Functions
    6. Multi-pattern catch clauses
    7. Typed Throws
    8. The availability attribute
    9. Unavailability
    10. Summary
  10. Regular Expressions
    1. Join our book community on Discord
    2. The Building Blocks of Regular Expressions
    3. Regular Expression Literals
    4. Regex type
    5. RegexBuilder
      1. Converting regular expressions to RegexBuilder
    6. Transform Match with RegexBuilder
    7. Capture Match with RegexBuilder
    8. Summary
  11. Custom Subscripting
    1. Join our book community on Discord
    2. Introducing subscripts
    3. Subscripts with Swift arrays
    4. Creating and using custom subscripts
      1. Read-only custom subscripts
      2. Calculated subscripts
      3. Subscript values
      4. Static subscripts
    5. External names for subscripts
    6. Multidimensional subscripts
    7. Extending Types with Subscripts
    8. When not to use a custom subscript
    9. Summary
  12. Property Observers and Wrappers
    1. Join our book community on Discord
    2. Property Observers
    3. Using Property Observers
    4. Property Wrappers
    5. Using Property Wrappers
    6. Summary
  13. Key Paths and Dynamic Member Lookup
    1. Join our book community on Discord
    2. Dynamic Member Lookup
    3. Key Paths
      1. Understanding Key Paths
      2. Key Paths in Functions
      3. Map and Filter Functions with Key Paths
    4. Summary
  14. Concurrency With Grand Central Dispatch
    1. Join our book community on Discord
    2. Concurrency and parallelism
    3. Grand Central Dispatch (GCD)
      1. Calculation types
      2. Creating queues
      3. Creating and using a concurrent queue
      4. Creating and using a serial queue
    4. async versus sync methods with GCD
    5. Executing code on the main queue function
    6. Using asyncAfter
    7. Dispatch Groups
    8. Barriers
    9. Dispatch Semaphores
    10. Summary
  15. Concurrency With Asynchronous Operations
    1. Join our book community on Discord
    2. Data-Race Conditions and Swift 6
    3. Asynchronous Functions
    4. Async and Await
    5. Tasks
    6. Task Groups
    7. Actors
    8. Sendable Types
    9. Summary
  16. Memory Management
    1. Join our book community on Discord
    2. How ARC works
    3. Strong reference cycles
      1. Unowned references
      2. Weak references
    4. Summary
  17. Advanced and Custom Operators
    1. Join our book community on Discord
    2. Bits and bytes
    3. Endianness
    4. Bitwise operators
      1. Printing binary numbers
      2. The bitwise AND operator
      3. The bitwise OR operator
      4. The bitwise XOR operator
      5. The bitwise NOT operator
      6. Bitwise shift operators
    5. BinaryInteger extension
    6. Overflow operators
    7. Operator methods
    8. Custom operators
    9. Summary
  18. Access Controls
    1. Join our book community on Discord
    2. Access Control Levels
      1. Open Access
      2. Public Access
      3. Internal Access
      4. File-Private Access
      5. Private Access
    3. Access Levels with Enumerations
    4. Access Controls for Getter and Setters
    5. Best Practices for Access Control
      1. Use the Most Restrictive Access Level by Default
      2. Encapsulate Implementation Details
      3. Use Extensions Wisely
      4. Maintain Consistency
    6. Summary
  19. Swift Testing
    1. Join our book community on Discord
    2. Getting Started with Swift Testing
      1. XCode Project
      2. Swift Package Manger
    3. Building Blocks for Swift Testing
      1. @Test Function
      2. Expectations
      3. Traits
      4. Suites
    4. Swift Testing Example
      1. Calculator
      2. @testable attribute
      3. Calculator Tests
    5. Summary
  20. Object-Oriented Programming
    1. Join our book community on Discord
    2. What is object-oriented programming?
    3. Requirements for the sample code
    4. Swift as an object-oriented programming language
    5. Issues with the object-oriented design
    6. Summary
  21. Protocol-Oriented Programming
    1. Join our book community on Discord
    2. Requirements for the sample code
    3. Swift as a protocol-oriented programming language
    4. Protocol Inheritance
    5. Protocol Composition
    6. Protocol Oriented Design
    7. Swift Standard Library
    8. Summary
  22. Functional Programming with Swift
    1. Join our book community on Discord
    2. Core Principles of Functional Programming
      1. Immutability
      2. Pure Functions
      3. First-Class Functions
      4. High-Order Functions
    3. Advanced Functional Programming Techniques
      1. Function Composition
      2. Currying
      3. Recursion
    4. Summary

Product information

  • Title: Mastering Swift 6 - Seventh Edition
  • Author(s): Jon Hoffman
  • Release date: November 2024
  • Publisher(s): Packt Publishing
  • ISBN: 9781836203698