<div dir="ltr">on Wed, 25 Oct 2017 13:41:40 +0200 David Hart <<a href="mailto:david@hartbit.com">david@hartbit.com</a>> wrote:<div><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
class A {<br>
func foo() {<br>
func local() {<br>
bar() // error: Call to method ‘bar' in function ‘local' requires explicit 'self.' to make capture semantics explicit<br>
}<br>
<br>
// ...<br>
}<br>
}<br></blockquote><div><br></div><div>it's not only about calling "bar"... any variable access will require self. which will be quite annoying, especially given the fact that "local" my not even be used in an escaping context discussed. (*)</div><div><br></div><div>i think it is more consistent to prepend local with self if it is used in an escaping context:</div><div><br></div><div><div>func foo() {</div><div><br></div><div> func local() {</div><div> bar() // no self needed here ever</div><div> variable = 1 // no self needed here, ever</div><div> }</div><div> </div><div> func otherLocal() {</div><div> print("i am not capturing self")</div><div> }</div><div> </div><div> DispatchQueue.main.async {</div><div> local() // error without self</div><div> self.local() // ok</div><div> otherLocal() // ok without self</div><div> }</div><div>}</div></div><div><br></div><div>(*) interestingly, closures always treat themselves as "escaping", even if it's not the case, e.g. even if i only use them in a non-escaping contexts. worth to add an explicit attribute to denote non-escaping closures?</div><div><br></div><div>let closure = @nonescaping {</div><div> print("i am not escaping")</div><div> variable = 1 // ok without self</div><div>}</div><div><br></div><div>DispatchQueue.main.async(execute: closure) // error, non escaping closure passed</div><div><br></div><div>Mike</div><div><br></div></div></div></div></div>