Static vs class functions/variables in Swift classes?
original source : https://stackoverflow.com/a/29636742
static
and class
both associate a method with a class, rather than an instance of a class. The difference is that subclasses can override class
methods; they cannot override static
methods.
class
properties will theoretically function in the same way (subclasses can override them), but they’re not possible in Swift yet.
- So what is the difference between
final class
function and ‘static’ function within a class? – hippo_sanJul 17 ’15 at 15:11 - @hippo_san, in a base class the two are functionally the same. However,
final
can be used to cut off further overrides when used in a subclass. The two both have their place, I would say the use ofstatic
orfinal
when used on a class function is trivial and up to your style choice. – Andrew Robinson Jul 27 ’15 at 20:36 - ah, so
static func foo(){}
in Swift is likepublic static final foo(){}
in Java? – SupuhstarAug 6 ’15 at 23:42 - @Supuhstar: Basically, yes