Protocols in Swift

Protocols are extremely important in Swift

Steven Curtis
5 min readJan 21, 2020

A protocol allows objects, and provide a concrete implementation of any object that conforms to it. We can think of a protocol as a set of rules and guidelines that an object can conform to

For the examples, read on.

Photo by Mike Meyers on Unsplash

Difficulty: Beginner | Easy | Normal | Challenging

Prerequisites:

  • Be able to produce a “Hello, World!” iOS application (guide HERE)
  • Use of extensions (guide HERE)
  • Some knowledge of Object-oriented programming, specifically overriding (guide HERE)

Terminology

class: An object defined in Swift, using pass by reference semantics

conforms: conformance is if an object adopts a protocol (or inherits it from another class) and contains the functionality specified

enum: A type consisting of a set of named values, called members

extensions: Extensions add new functionality to a class, struct, enum or protocol

inheritance: The mechanism in which one class acquires the property of another class

method: A group of statements that together can perform a function

--

--

No responses yet