Even though no functionality is implemented in a protocol, they are still considered a full-fledged type in the Swift programming language and can be used like any other type. What this means is we can use protocols as a parameter type or as a return type in a function. We can also use them as the type for variables, constants, and collections. Let's take a look at some examples. For these few examples, we will use the PersonProtocol
protocol:
protocol PersonProtocol { var firstName: String {get set} var lastName: String {get set} var birthDate: NSDate {get set} var profession: String {get} init (firstName: String, lastName: String, birthDate: NSDate) }
In this first example, we will see how we would use protocols as a parameter type or return type in functions, methods, or initializers:
func updatePerson(person: PersonProtocol) -> PersonProtocol { // Code to update person goes here return person }
In this example...