An existential is essentially a "box" that can hold a value of any concrete type conforming to a protocol P
, or at least that's how I think of it at a high level. Here's a quote from Improving the UI of generics that offers a bit more information:
Swift also has existential types, which provide value-level abstraction . By contrast with a generic type parameter, which binds some existing type that conforms to the constraints, an existential type is a different type that can hold any value of any type that conforms to a set of constraints, abstracting the underlying concrete type at the value level. Existentials allow values of varying concrete types to be used interchangeably as values of the same existential type, abstracting the difference between the underlying conforming types at the value level . Different instances of the same existential type can hold values of completely different underlying types, and mutating an existential value can change what underlying type the value holds
2 Likes