That little Swift Bug: Protocol Customization Points

Photo by Gavin Allanwood

The issue

Let us first take the code. If we accept that tents can be a type of building, and that dome tents and tunnel tents are indeed tents, this will help us to understand the following example:

The solution

The building protocol can define a Method Requirement within the Building protocol.

The theory

What is happening behind the scenes is the difference between Static Dispatch and Dynamic Dispatch.

Conclusion

Static and dynamic types can be a little tricky when we are coding in Swift! This should be considered far from Apple communicating this as a language feature (or not), but rather is informed by the inner working of static and dynamic dispatch.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store