2

I read, that it's always best practice to call super.method(), if you override a method.

However, overriding the perform() method of an UIStoryboardSegue and calling super.perform() throws an exception. If i'm not calling super.perform(), it's working fine.

Why?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • 1
    Possible duplicate of [When should I call super?](https://stackoverflow.com/questions/3906704/when-should-i-call-super). – As noted in the answers, there is no general rule, you have to consult the documentation of the respective method. – Martin R Jun 11 '17 at 09:17
  • In more simple words: Apple specifies when it needs to call a the `super.method()` because the mother class do some "important" stuff by code hidden by Apple (triggers calls, etc.). For instance, for `UICollectionViewCell` `prepareForReuse()` "The default implementation of this method does nothing. However, when overriding this method, it is recommended that you call super anyway.". In the future they may add code that internally should be called. In your own code, you may sometimes avoid that when you subclass. It's proper to each case/scenario. – Larme Jun 11 '17 at 10:44

1 Answers1

1

Some methods are not supposed to be called directly. Refer the documentation. For example, you should not call [Super loadView] in loadView of your subclass but you can call [Super viewDidLoad] when overriding viewDidLoad.Ref:https://developer.apple.com/documentation/uikit/uiviewcontroller/1621454-loadview?preferredLanguage=occ

In such cases, subclasses need to have their own implementation not just extending the behaviour of super's implementation.

singhabhi13
  • 227
  • 1
  • 7