Within a protocol, Self
refers generically to the conforming type. You can see how this Self
behaves differently from covariant Self
in classes by declaring a subclass of A
:
protocol P {
typealias _Self = Self
}
class A: P {
@Published<_Self?>
var a: _Self?
var a2: Self? { return nil } // 'covariant Self'
}
class B: A {
}
print(type(of: B().a)) // Optional<A>
print(type(of: B().a2)) // Optional<B>