[swift-evolution] Proposal: Re-instate mandatory self for accessing instance properties and functions

David Smith david_smith at apple.com
Fri Dec 4 15:21:37 CST 2015


Currently, ‘self.’ is required when used in closure capture contexts, which has the nice property of making it really clear when things are being captured (and therefore retained).

	David

> On Dec 4, 2015, at 1:19 PM, David Hart <david at hartbit.com> wrote:
> 
> I don't understand the reasoning behind removing the need to access instance properties and functions using self. Swift has always seemed to prefer readability to brevity and the feature makes the distinction between local and instance variables/functions crystal clear. Any good reason I shouldn't go on with the proposition?
> 
> Just as example, my proposition makes the following piece of code illegal:
> 
> ```
> struct FooBar {
>    var foo: String = "foobar"
> 
>    func bar() {
>        print(foo) // compiler error
>        print(self.foo) // compiler happy
>    }
> 
>    func bar2() {
>        bar() // compiler error
>        self.bar() // compiler happy
>    }
> }
> ```
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list