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

Félix Cloutier felixcca at yahoo.ca
Thu Dec 17 10:05:08 CST 2015


I think that this is not what Stephen meant. This `guard` statement creates a `foo` local only if `self.foo` is not nil. From there on, the unwrapped `foo` local will shadow the `foo` member.

> Le 17 déc. 2015 à 09:20:30, Jeremy Pereira via swift-evolution <swift-evolution at swift.org> a écrit :
> 
> 
>> On 17 Dec 2015, at 14:22, Stephen Celis <stephen.celis at gmail.com> wrote:
>> 
>>> On Dec 17, 2015, at 4:54 AM, Jeremy Pereira via swift-evolution <swift-evolution at swift.org> wrote:
>>> 
>>> There are other ways to achieve the goal, for example Java has a warning that explicitly tells you when your local variable is shadowing an instance variable. Why wouldn’t that work?
>> 
>> The main arguments I've seen are around initializers and let-unwrapping:
>> 
>>    init(foo: Int) {
>>        self.foo = foo
>>    }
>> 
>>    guard let foo = foo else { return }
>> 
>> I'm curious if there are more. I think both of these could be special-cased.
>> 
>> Stephen
> 
> 
> In Java, I have the warning enabled for local variables but not function arguments precisely so that I can use the  this.x = x pattern in constructors. The pattern is so common in Swift that I would that the init is explicitly excluded and so are the optional binding statements and guard.
> _______________________________________________
> 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