Absence of methods in swift code

Hi, I’ve recently been following an example piece of code where there are no methods like viewdidload, or viewwillappear,etc. within a main view controller . And yet the code still seems to function perfectly fine? I think I’m write in saying the uiviewcontroller will inherit these methods anyway. My question is ,are there certain assumption made by the compiler about what to do in the absence of these ? ( sorry , I’m still new to all)

What do you mean assumptions? When faced with non-final classes and inheritance, the Swift compiler is most likely going to be unable to turn dynamic dispatch into static dispatch. So it's not going to be making many assumptions about what method to call.

Swift classes, like other languages, inherit from their superclass.

Unless you want to override a method, you don’t need to type it again.

2 Likes

In, object oriented programming, a class can inherit from another, and the child/sub class will retain the methods, properties and behavior of its parent/super class.

For a trivial subclass, where you declare no additional properties or methods, for all intents and purposes, the subclass will be exactly like its superclass.

A subclass of e.g UIViewController will inherit viewDidLoad etc. Unless you override it, it will behave exactly like a vanilla, non-specialized view controller.

However, you may override one or more of superclass’s methods, specializing it, by performing additional computations before or after calling super to allow it to do its thing.

Not overriding a function is equivalent to overriding it with just a single call to super.

1 Like