-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Swift Functional Programming
By :

POP encourages us to develop protocols and extend them instead of classes and inheritance. POP is new in the Objective-C and Swift development community, but what it provides is not very different from the concept of Abstract
classes in languages such as Java and C#, and pure-virtual
functions in C++.
In Swift, classes, structs, and enumerations can conform to protocols. This makes protocols more usable because inheritance does not work for structs and enumerations.
In this section, we will explore POP paradigms. To start with, we will look at an example:
protocol UserProtocol { func greet(name: String) -> String func login(username: String, password: String) -> Bool }
This protocol defines two functions to be implemented by the struct, enumeration, or classes that need to conform to this protocol.
Protocol composition allows types to conform to more than one protocol. This is one of the many advantages that POP has over OOP. With OOP, a...