[swift-users] How self automatically becomes Self type if the function's return type is Self?

Zhao Xin owenzx at gmail.com
Sat Aug 27 09:05:24 CDT 2016


See the code:

protocol Foo {

    func instance() -> Self

}


class Bar: Foo {

    func instance() -> Self {

        return self // Declaration: let `self`: Self

    }

    func other() {

        let i = self // Declaration: let `self`: Bar

    }

}

How does it happen?


Zhaoxin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160827/c2a0d659/attachment.html>


More information about the swift-users mailing list