While playing in a Swift playground I noticed that Self
, with capital "S", is available along with the lowercase self
. Is there any difference between them? If so, what are usages for these two, especially for Self
?
Self
refers to the type of the current "thing" inside of a protocol (whatever is conforming to the protocol). For an example of its use, see Protocol func returning Self.
The official docs I've found for Self
is in Protocol Associated Type Declaration in The Swift Programming Language. It surprisingly is not documented in the sections on protocols or on nested types:
However, now there is a paragraph about Self Type
including a code example in the official Swift Programming Language's chapter about Types