<div dir="ltr">I've been reading the discussion in "Final by default for classes and methods" and although I don't have a strong position towards what the default behaviour should be, I think a directive to change that behaviour should be added as when nullability was introduced into Obj-C.<div><br></div><div>In the current model of Swift, where methods and classes are not final we can ease that by doing something like this:</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(4,51,255)">ASSUME_FINAL_BEGIN</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(4,51,255)">class</span> MyClass {</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(4,51,255)">func</span> aMethod(arg: <span style="color:rgb(52,149,175)">String</span>) {</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> </p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> </p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(4,51,255)">func</span> anotherMethod(number: <span style="color:rgb(52,149,175)">Int</span>) {</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> </p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(4,51,255)">ASSUME_FINAL_END</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(4,51,255)"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(4,51,255)"><br></p>In this example the whole class is treated as final by the compiler.</div><div>On the other hand, in the following example:</div><div><br></div><div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(4,51,255)">class<span style="color:rgb(34,34,34)"> </span><span style="color:rgb(34,34,34)">MyClass {</span><br></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(4,51,255)">ASSUME_FINAL_BEGIN</span><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(4,51,255)">func</span> aMethod(arg: <span style="color:rgb(52,149,175)">String</span>) {</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> </p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="color:rgb(4,51,255)">ASSUME_FINAL_END</span> </p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(4,51,255)">func</span> anotherMethod(number: <span style="color:rgb(52,149,175)">Int</span>) {</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> </p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">Only aMethod is final, leaving the rest to the default behaviour. (Ok, the example is not different to prepending 'final' but you get the idea).</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">Similarly, should the classes and methods become final by default, a directive to do the opposite should be added (ASSUME_OVERRIDEABLE_(BEGIN|END)?)</p></div></div><div><br></div><div>-- <br></div><div>++++++++++++++++++++++++++<br>Diego Torres.</div></div>