Book Image

Protocol-Oriented Programming with Swift

By : Jon Hoffman
Book Image

Protocol-Oriented Programming with Swift

By: Jon Hoffman

Overview of this book

<p>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.</p> <p>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.</p> <p>By the end of this book readers will be able to harness the power of protocol-oriented programming to build real world applications.</p>
Table of Contents (14 chapters)
Protocol-Oriented Programming with Swift
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Calculator application


In this case study we will create a very simple calculator application. This application will give the user the ability to add, subtract, multiply, and divide whole or decimal numbers.

We will not go through how to set up the application or the UI design in this section. We will leave that up to you, the reader. This will let you design the UI as you want to and also allow you to build the application as an iOS or an OS X application. You could even build it as a Linux-based application since Swift is now open source.

You can download my iOS calculator application with the code bundle for this book. My design looks like the following screenshot:

Now let's look at the requirements.

Requirements

Here are the requirements for our application:

  • The calculator needs the ability to add, subtract, multiply, and divide

  • We need the ability to clear the current calculation

  • We need the ability to clear the last number pressed

  • We need to be able to display the value of the current calculation...