-1

I have model and in this model contains a function to SUM 1 + 1 Why should I have to make this function non-static?

The difference is an only instantiable class or not?

Calling static function in Controller

Model.sumFunction()

Calling non-static function in Controller

let model = Model()
model.sumFunction

What's a real difference?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
ari
  • 149
  • 7
  • 4
    http://stackoverflow.com/questions/29636633/static-vs-class-functions-variables-in-swift-classes – boidkan Sep 16 '16 at 15:17

1 Answers1

1

The difference is that SubClass of your model class can override non static function whether is class or instance. but SubClass can't override static function.

And the reason behind that is static get one time memory allocation and remains in memory until class remains in memory!

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • depends on need. generally we are not using static functions. If we need something that not need to allocate memory everytime whatever the reason then we should use static. For, example we generally declare `static identifier` in `cellforrowatindexpath` method becoz identifier will always be same and this method call too many time so make it static is better! – Ketan Parmar Sep 16 '16 at 15:25
  • Thanks! But if I do everything in static class, what is the problem that I will have in the future? – ari Sep 16 '16 at 15:32
  • 1
    Refer [https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Methods.html](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Methods.html) – Ketan Parmar Sep 16 '16 at 17:40