While playing in a Swift playground I noticed that Self
, with capital \"S\", is available along with the lowercase self
. Is there any difference be
Self can also be used as a return type in the protocol extension method body which will return confirming type instance, and for type casting with "as". Please see example below:
extension where Self: {
static func foo(_ param:Type)-> Self{
guard let abc = method() as? Self else{
return xyz
}
}}
In the nutshell, Self can be used to refer the Type which confirms to the protocol.