Nested Protocol

Is there a particular reason for not being allowed to declare a protocol nested inside another declaration? It seems reasonable to me to establish a direct relationship between a type and a protocol, when the latter has its use restricted within the scope of the former, for example.

Is there a particular use case, in terms of types, that you would want this - or are you actually trying to do it as a way of namespacing?

Afaics there are no fundamental problems with nesting protocols in other types — unless the outer type is generic, as this would basically introduce generic protocols (which I personally consider to be quite useful... alas, our leaders seem to have a different opinion).

Maybe there is a stronger justification, but imho it would be a weird limitation to allow nesting only in some cases.

Namespacing indeed :smile:

There are impacts to Swift's type system to allow nested protocols that just haven't been addressed yet by Swift Evolution, so because of that, the plan so far is to be consistent in not allowing nesting at all.

1 Like