Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardSwiftstatic vs dynamic witness dispatchSingle-choice MCQ

Consider this protocol with a default method and a non-requirement method. Why does calling `m()` on a `P`-typed existential dispatch dynamically to `A`'s override, while `extra()` does NOT?

protocol P { func m() } extension P { func m() { print("P.m") } func extra() { print("P.extra") } } struct A: P { func m() { print("A.m") } func extra() { print("A.extra") } } let x: P = A() x.m() x.extra()