Protocol Extensions in Swift

You can extend protocols too!

Steven Curtis
3 min readApr 16, 2020

Protocol extensions are extremely powerful in Swift, but contain a couple of inherent limitations. To learn what they are, read on!

Difficulty: Beginner | Easy | Normal | Challenging

Prerequisites:

  • Be able to produce a “Hello, World!” iOS application (guide HERE)
  • Use of extensions in Swift (guide HERE)

Terminology

class: An object that defines properties and methods in common

Conform: Conforming to a protocol means that anything that conforms to the protocol contains the necessary behaviours specified

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

protocol: A blueprint on methods, properties and requirements to suit a piece of functionality

struct: An object defined in Swift, using pass by value semantics

Why extend a protocol?

A protocol allows objects, and provide a concrete implementation of any object that conforms to it. This allows addition of functionality into any types that conform to the protocol, and even better we can extend the functionality without changing the…

--

--