0%

Book Description

Build fast and powerful applications by exploiting the power of protocol-oriented programming in Swift

About This Book

  • The only book that shows how to harness the power of Protocol-Oriented Programming in Swift to build real-world applications,
  • Get familiar with the protocol focused approach of application development,
  • 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 their real world applications.

What You Will Learn

  • The difference between Object-Oriented programming and Protocol-Oriented programming
  • The difference between reference and value types and when to use each
  • How we can leverage tuples to reduce the complexity of our code
  • What are protocols and how to use them
  • How to implement protocol extensions to create a very flexible code base
  • How to implement several design patterns in a Protocol-Oriented approach
  • How to solve real world design issue with protocol oriented programming

In Detail

At the heart of Swift's design is an incredibly powerful idea: protocol-oriented programming. Its many benefits include better code maintainability, increased developer productivity and superior application performance. The book will teach the reader how to apply the ideas behind the protocol oriented programing paradigm to improve the code they write.

This book will introduce the readers to the world of protocol-oriented programming in Swift and will demonstrate the ideas behind this new programming paradigm with real world examples. In addition to learning the concepts of Protocol Oriented programming, it also shows the reader how to reduce the complexity of their codebase using protocol extensions. Beginning with how to create simple protocols, readers will learn how to extend protocols and also to assign behaviors to them.

By the end of this book readers will be able to harness the power of protocol-oriented programming to build real world applications.

Style and approach

In its latest release of Swift, Apple has introduced Protocol Extensions as a new feature at the heart of Swifts design making Swift 2 a protocol-oriented language. Protocol oriented programming being a less explored OOP paradigm, there is little guidance on hot to take advantage of protocol extensions in real-world applications. In addition to offering an in-depth coverage of protocol oriented programming and its concepts, this book also explains how a developer can leverage these features to build powerful, real-world applications

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. Protocol-Oriented Programming with Swift
    1. Table of Contents
    2. Protocol-Oriented Programming with Swift
    3. Credits
    4. About the Author
    5. About the Reviewer
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. 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. Errata
        3. Piracy
        4. Questions
    8. 1. Object-Oriented and Protocol-Oriented Programming
      1. Swift as an object-oriented programming language
      2. Swift as a protocol-oriented programming language
      3. Summarizing protocol-oriented programming and object-oriented programming
      4. Object-oriented programming versus protocol-oriented programming
        1. Protocol and protocol extensions versus superclasses
        2. Implementing drink types
        3. Value types vs reference types
      5. The winner is...
      6. Summary
    9. 2. Our Type Choices
      1. The class
      2. The structure
      3. The enumerations
      4. The tuple
      5. Protocols
      6. Value versus class types
      7. Recursive data types (reference types only)
      8. Inheritance (reference types only)
      9. Swift built-in data types and data structures
      10. Summary
    10. 3. Catching Our Errors
      1. Using the guard statement
      2. Error handling
      3. Error handling with return values
      4. Error handling with NSError
      5. Error handling with Swift 2
        1. Representing errors
        2. Throwing errors
        3. Catching errors
      6. When to use error handling
      7. Summary
    11. 4. All about the Protocol
      1. Protocol syntax
        1. Defining a protocol
        2. Property requirements
        3. Method requirements
        4. Optional requirements
        5. Protocol inheritance
      2. Protocol composition
      3. Using protocols as a type
      4. Polymorphism with protocols
      5. Type casting with protocols
      6. Associated types with protocols
      7. Delegation
      8. Designing and developing with protocols
      9. Summary
    12. 5. Let's Extend Some Types
      1. Defining an extension
      2. Protocol extensions
      3. Text validation
      4. Summary
    13. 6. 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 façade pattern
          1. Understanding the problem
          2. Understanding the solution
          3. Implementing the façade 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. 7. Case Studies
      1. Logging service
        1. Requirements
        2. The design
        3. Conclusion
      2. Data access layer with SQLite.swift
        1. Requirements
        2. The design
        3. Connection layer
        4. Data model layer
        5. Data helper layer
        6. Conclusion
      3. Calculator application
        1. Requirements
        2. The design
        3. Conclusion
      4. Summary
    15. Index
18.218.55.14