You are previewing Swift 3 Protocol-Oriented Programming - Second Edition.
O'Reilly logo
Swift 3 Protocol-Oriented Programming - Second Edition

Book Description

Build fast and powerful applications with the power of protocol-oriented programming

About This Book

  • Leverage the power of protocol-oriented programming in your applications and learn from real world use cases

  • Create a flexible codebase with protocols and protocol extensions

  • Increase the overall productivity and performance of applications with protocol-oriented programming

  • Who This Book Is For

    This book is for Swift developers who want to learn and implement protocol-oriented programming in practical applications.

    What You Will Learn

  • Understand the difference between object-oriented programming and protocol-oriented programming

  • Explore the different types that Swift offers and what pitfalls to avoid

  • Error handling with do-try-catch block

  • Delve into Generics and Generic programming

  • Implement several design patterns in a protocol-oriented way

  • How to design applications by prioritizing the protocol first and the actual type second

  • In Detail

    One of the most important additions to the new features and capabilities of the Swift programming language was an overhaul of Protocols. Protocol-oriented programming and first class value semantics have now become two incredibly powerful concepts at the heart of Swift’s design.

    This book will help you understand the difference between object-oriented programming and protocol-oriented programming. It will demonstrate how to work with protocol-oriented programming using real world use cases. You will gain solid knowledge of the different types that can be used in Swift and the differences between value and reference types. You will be taught how to utilize the advanced features of protocol-oriented programming to boost the performance of your applications.

    By the end of the book, you will have a thorough understanding of protocol-oriented programming and how to utilize it to build powerful, practical applications.

    Style and approach

    This book is written for developers who learn best by working with code, so every concept discussed in this book is reinforced with real code examples.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. Swift 3 Protocol-Oriented Programming - Second Edition
      1. Swift 3 Protocol-Oriented Programming - Second Edition
      2. Credits
      3. About the Author
      4. About the Reviewer
      5. www.PacktPub.com
        1. Why subscribe?
      6. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      7. 1. Object-Oriented and Protocol-Oriented Programming
        1. What is object-oriented programming?
        2. Requirements for the sample code
        3. Swift as an object-oriented programming language
        4. Drawbacks to object-oriented design
        5. Swift as a protocol-oriented programming language
        6. Summarizing protocol-oriented programming and object-oriented programming
        7. Differences between object-oriented programming and protocol-oriented programming
          1. Protocol and protocol extensions compared with superclasses
          2. Implementing vehicle types
        8. The winner is...
        9. Summary
      8. 2. Our Type Choices
        1. The class
        2. The structure
        3. Access controls
        4. The enumerations
        5. The tuple
        6. Protocols
        7. Value and reference types
        8. Recursive data types for reference types only
        9. Inheritance for reference types only
        10. Swift's built-in data types and data structures
        11. Summary
      9. 3. Catching Our Errors
        1. Using the guard statement
        2. Error handling
        3. Error handling with return values
        4. Error handling with do-catch
          1. Representing errors
          2. Throwing errors
          3. Catching errors
        5. Using the defer statement
        6. When to use error handling
        7. Summary
      10. 4. All About the Protocol
        1. Protocol syntax
          1. Defining a protocol
          2. Property requirements
          3. Method requirements
          4. Optional requirements
        2. Protocol inheritance
        3. Protocol composition
        4. Using protocols as a type
        5. Polymorphism with protocols
        6. Type casting with protocols
        7. Associated types with protocols
        8. Delegation
        9. Designing and developing with protocols
        10. Summary
      11. 5. Lets Extend Some Types
        1. Defining an extension
        2. Protocol extensions
        3. Text validation
        4. Summary
      12. 6. Working with Generics
        1. Generic functions
        2. Type constraints with generics
        3. Generic types
        4. Associated types
        5. Generics in a protocol-oriented design
        6. Summary
      13. 7. Adopting Design Patterns in Swift
        1. What are design patterns?
        2. Creational patterns
          1. The singleton design pattern
            1. Understanding the problem
            2. Understanding the solution
            3. Implementing the singleton pattern
          2. The builder design pattern
            1. Understanding the problem
            2. Understanding the solution
            3. Implementing the builder pattern
          3. The factory method pattern
            1. Understanding the problem
            2. Understanding the solution
            3. Implementing the factory method pattern
        3. Structural design patterns
          1. The bridge pattern
            1. Understanding the problem
            2. Understanding the solution
            3. Implementing the bridge pattern
          2. The facade pattern
            1. Understanding the problem
            2. Understanding the solution
            3. Implementing the facade pattern
          3. The proxy design pattern
            1. Understanding the problem
            2. Understanding the solution
            3. Implementing the proxy pattern
        4. Behavioral design patterns
          1. The command design pattern
            1. Understanding the problem
            2. Understanding the solution
            3. Implementing the command pattern
          2. The strategy pattern
            1. Understanding the problem
            2. Understanding the solution
            3. Implementing the strategy pattern
          3. The observer pattern
            1. Understanding the problem
            2. Understanding the solution
            3. Implementing the observer pattern
        5. Summary
      14. 8. Case Studies
        1. Logging service
          1. Requirements
          2. The design
          3. Conclusion
        2. Data access layer
          1. Requirements
          2. The design
          3. Data model layer
          4. Data helper layer
          5. Bridge layer
          6. Using the data access layer
          7. Conclusion
        3. Calculator application
          1. Requirements
          2. The design
          3. Conclusion
        4. Summary