DevPrep

All topics › The Swift Language

What kinds of method dispatch does Swift have?

Middle PRO

The idea

Dispatch is how the compiler locates a method's implementation at a call site. Swift has four kinds, from fastest to most flexible:

Which one the compiler picks depends on the static type of the variable used for the call and on where the method is declared (type body, extension, protocol).

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store