This is a valid protocol declaration in Swift:
protocol Proto1: class {
func method1() -> Self
func method2() -> [Proto1]
}
But this isn't:
protocol Proto2: class {
func method1(param: Self)
func method2() -> [Proto2]
}
The error message is:
Protocol 'Proto2' can only be used as a generic constraint because it has Self or associated type requirements
So it seems that, when using Self as function's return type, Swift doesn't consider that as a constraint of the protocol being defined and hence it's OK to use the protocol itself as functions' return type. But when using Self as function's parameter type, the behavior is completely different.
I wonder why such a difference?