Swift & Concurrency (50 Qs)•Part 3: Runtime Internals, Swift 6 Safety & Systems Programming (25 - 35)
Existential Any vs Opaque Some Types (`any Protocol` vs `some Protocol`).
senior LevelswiftRuntime Internals
In Simple Words:
- Opaque Types (
some View/some Protocol):- Represents a specific, fixed concrete type chosen by the implementation, hidden from the caller.
- Zero performance overhead (static dispatch).
- Existential Types (
any Protocol):- A dynamic box that can hold any arbitrary type conforming to the protocol at runtime.
- Incurs memory heap allocation for values larger than 3 words (Existential Container) and dynamic witness table dispatch.