Method Dispatch in Swift Protocols and Inheritance
Runtime or Compile time?
5 min readAug 11, 2022
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 11.5, and Swift 5.2.4
Prerequisites:
- 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.
Terminology:
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