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. This means that 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 following PersonProtocol protocol:
protocol PersonProtocol { var firstName: String { get set } var lastName: String { get set } var birthDate: Date { get set } var profession: String { get } init(firstName: String,lastName: String, birthDate: Date) }
In this first example, a protocol is used as a parameter type and a return type for a function:
func updatePerson(person: PersonProtocol) -> PersonProtocol { // Code to...