NikMos NikMos - 1 year ago 84
iOS Question

Need to call super constructor for lifecycle methods in Swift

I've been coding for some years now, and I'm very used to always calling a method's super constructor when overriding it. But recently I've been wondering if it's always necessary... I get that when you override an initialiser you should call

. But in Swift and iOS development, if you override a
lifecycle method like
and forget to call
, the compiler dosen't produce any warning or error and the code seems to be compiling fine. So I was wondering if the call is somehow build into the SDK, and if it's even necessary to make (with in mind that we want to make the code as efficient and correct as possible)?

Answer Source

I think you may look here a nice answer.

Apple doesn't restrict you to call super.viewDidLoad(), but it won't be safe to use some view cycle methods and variable before it's call. If you want first to init your own vars or properties for example - I think, it won't be a problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download