1

I am looking for the difference between static and class keyword in swift. Where do i need to use static vs class.

For e.g;

class MyClass {

    static func firstMethod() {}

    class func secondMethod() {}
}

 func doSomething() {
     myClass.firstMethod()
     myClass.secondMethod()
 }

So we can use like this;

MyClass.secondMethod()

MyClass.firstMethod()

So where should i use static or class?

Community
  • 1
  • 1
Vikash Sinha
  • 869
  • 1
  • 7
  • 21
  • 1
    Does this answer your question? [What is the difference between static func and class func in Swift?](https://stackoverflow.com/questions/25156377/what-is-the-difference-between-static-func-and-class-func-in-swift) – chirag90 Jan 28 '20 at 11:28

1 Answers1

1

In general its enough to use static keyword, but Apple provide description that if you use struct - use static , if class - use class

static is same as class final

But i recommend to read article below, i hope everything will become cleaner after reading https://borgs.cybrilla.com/tils/global-vs-static-function-swift/