Reputation: 223
What is the difference between static
and final
keywords in Swift? When should each be used?
I understand that for a static
Class nothing can inherit from it, but that is also true for final
.
Thank you
Upvotes: -2
Views: 7117
Reputation: 4160
Common thing between Static and Class is, that they both attaches variables to the Class itself and not to the instance of class.
Where they differ is, you CAN OVERRIDE class properties whereas in case of static you CAN NOT OVERRIDE it in subclass.
Hope this this helps.
Upvotes: 1
Reputation: 81
Note: static is same with "final class" for class members
Upvotes: 1
Reputation: 223
So, after a while research I would say that static is used for a property that can be accessed without created a class instance and final is a modifier for a class that from this class nobody can be inherent.
Upvotes: 8