<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">Swift has its own suggested patterns on calling methods. For example, it suggests you calling instance methods directly inside class. It also forces you calling self.method() in closure that without @noescape. As well as the static method with the class name in your question. Those are different from C++. But it does differ the differences between methods.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 1, 2016 at 10:01 AM, Rick Mann <span dir="ltr"><<a href="mailto:rmann@latencyzero.com" target="_blank">rmann@latencyzero.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Jun 30, 2016, at 18:47 , zh ao <<a href="mailto:owenzx@gmail.com">owenzx@gmail.com</a>> wrote:<br>
><br>
> Just a choice made by the language designers to distinguish the call at the call site.<br>
><br>
> You should be aware of using static methods as it may change static variables, which affects all instances of that class. Normally I think static methods is designed to use outside the class instance, if you have to use it inside its instance method. You may need to rethink the pattern you do.<br>
<br>
</span>I think of static methods as applying to all instances, and so code them to "behave properly" no matter how they're called (since I can't really control who calls it, unless it's my own class). Since it's implicitly obvious (to me) that I mean "this class" when I call one, I find it a bit tedious qualify the call with the class name.<br>
<br>
It's fine, in the end, but I was curious why it was like this, and if there was a more obvious reason why it needed the qualification.<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> Zhaoxin<br>
><br>
> On Fri, Jul 1, 2016 at 8:59 AM, Rick Mann via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
> Why can my instance methods not call class methods without the class specifier?<br>
><br>
> class MyClass<br>
> {<br>
> func<br>
> foo()<br>
> {<br>
> classMethod()<br>
> }<br>
><br>
> class<br>
> func<br>
> classMethod()<br>
> {<br>
> }<br>
> }<br>
><br>
> Why do I have to call MyClass.classMethod()? Just a choice made by the language designers to distinguish the call at the call site? I like C++'s way of treating all static methods as directly available to the instance.<br>
><br>
> --<br>
> Rick Mann<br>
> <a href="mailto:rmann@latencyzero.com">rmann@latencyzero.com</a><br>
><br>
><br>
> _______________________________________________<br>
> swift-users mailing list<br>
> <a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
><br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Rick Mann<br>
<a href="mailto:rmann@latencyzero.com">rmann@latencyzero.com</a><br>
<br>
<br>
</font></span></blockquote></div><br></div>