[swift-users] Why can't Swift instance methods call class methods without qualification?

Jens Alfke jens at mooseyard.com
Fri Jul 1 11:58:33 CDT 2016


> On Jul 1, 2016, at 9:38 AM, zh ao <owenzx at gmail.com> wrote:
> 
> Swift forces you to use class name to alert you on the fact that static variables and methods (may) affect the other instances of the class as static variables are shared between instances. That does make sense.

I disagree. Both static and instance methods can affect other instances of the class. In other words, just looking at these two calls:
	something()
	MyClass.something()
there’s no way to tell whether either or both of them change class-wide state. (To spell it out clearly: the implementation of the instance method something() might change the variable MyClass.staticState.)

I think the reasoning behind this syntax is simply to make it easy to distinguish usages of static members (methods or variables) from instance ones.

—Jens


More information about the swift-users mailing list