[swift-evolution] [Pitch] Adding a Self type name shortcut for static member access

Erica Sadun erica at ericasadun.com
Mon Apr 4 13:00:21 CDT 2016

Are there reasons that prevent using `Self` as a synonym for an instance's type name?


struct MyStruct {
    static func foo() { print("foo") }
    func bar() {
        MyStruct.foo() // works
        self.dynamicType.foo() // works
        Self.foo() // error

Obviously, you can always name a type directly or use `self.dynamicType` but
neither solution does any favors for readability. Both approaches obscure intent, 
especially as type names grow large: `MyExtremelyLargeTypeName.staticMember`,
for example. Plus, as Kevin B pointed out to me,  `self.dynamicType.classMember`  
and `TypeName.classMember` may not be synonyms in class types with non-final members.

I'd like to see `Self.staticMember` introduced as a synonym for `TypeName.staticMember`.


-- E

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160404/22b0fc37/attachment.html>

More information about the swift-evolution mailing list