Method Dispatch in Swift Protocols and Inheritance

Runtime or Compile time?

Steven Curtis
5 min readAug 11, 2022


Photo by Tolga Ulkan on Unsplash

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 11.5, and Swift 5.2.4


  • You will be expected to be aware how to make a Single View Application in Swift.
  • You should know something about Protocols in Swift
  • It would be useful to understand something about Polymorphism in Swift, since Dispatch is about polymorphic operation calls.


Compile time: the time in which the programming code is converted to the machine code

Dispatch: The process of selecting which implementation of polymorphic operation to call at runtime

Dynamic Dispatch: A form of polymorphism resolved at run time. Reference types

Method Requirements: Specifc instance and type methods to be implemented by conforming types

Runtime: The period of time where a program is running

Static Dispatch: A form of polymorphism fully resolved at compile time. Applies to Value and reference types

The Polymorphic example

The following code shows (a rather noddy and basic) use of polymorphism:

which prints the following to the console:

By using inheritance and overriding, we are able to expand the features available from a parent Animal class. Each Animal is…