[swift-evolution] [RFC] #Self

Vladimir.S svabox at gmail.com
Tue May 10 13:38:17 CDT 2016


On 10.05.2016 20:50, Matthew Johnson wrote:
> No, the whole point is that D.f() returns C because C is the requirement
> of 'f' is declared to return #Self which is C where the protocol
> conformance is declared and implemented.  If you want a covariant
> requirement you would use Self as the return type, not #Self.

I just followed your example with NSURL.. Probably I don't understand the 
point, but you said you want to conform a non-final class to protocol with 
method -> #Self.

 >---------------------<
protocol A { static func createWithString(s: String) -> Self }
extension NSURL: A { // cannot conform because NSURL is non-final }

If we could define a protocol requirement that didn't covary (using
#Self or whatever) we would be able to write the desired conformance.
 >---------------------<

And I don't understand how do you want to achieve the target, as even if we 
'invent' #Self, this (as I understand) can't work as class is not final. 
Just like with 'simple' Self - class must be final to conform. Thank you 
for clarification.


More information about the swift-evolution mailing list