Compare Static and Class Keyword in Swift
First of all, we will look into below example:
How is different? Yup, nothing! So why do both of them exist?
In the following, we will look at their similarities and differences and we will know why they both exist.
As above example, they can use for method type. But what will happen if another class inherit from them:
Now you can see we can not override for method type with static keyword.
Let see how about with struct?
Yay, method type with class keyword can not apply in struct, this is same in enum. So we see that class keyword only apply for reference type, not value type.
All above examples, we just go through for methods how about properties, let see:
Actually class keyword can not apply for stored properties. But both of them can use for computed properties:
Conclusion: we can conclude the similarities and differences as in the following table:
Thanks for reading!