0
override func viewDidLoad() {
    super.viewDidLoad()
    print(" viewDidLoad")
    // Do any additional setup after loading the view, typically from a nib.
}

there is any problem if super.viewDidLoad() from above function

Eldhose Elias
  • 389
  • 1
  • 6
  • 22
  • Also Related: https://stackoverflow.com/questions/844195/super-viewdidload-convention https://stackoverflow.com/questions/824695/do-i-always-have-to-call-super-viewdidload-in-the-viewdidload-method – Ahmad F Aug 13 '18 at 07:17
  • See as per the apple doc. you should call super.viewDidLoad method because it may do some initial setup for your parent/super class as your customVC class is inherited from VC class. If you don't do this also it works fine but in some cases it may show unpredictable behavior. – vivekDas Aug 13 '18 at 07:20

2 Answers2

0

Yes, it takes away the opportunity of the super to do anything in viewDidLoad().

If the super doesn't do anything (which may be the case if you are subclassing UIViewController directly), then you may not see any immediate difference. But if you were to subclass the class you just wrote and not call the super, for example, then your print would not be called.

See more: Do I always have to call [super viewDidLoad] in the -viewDidLoad method?

vievievie
  • 328
  • 3
  • 10
0

For a VC inheriting from UIViewController, not calling super.viewDidLoad makes no difference.

However, when you have a VC that inherits from a class that actually does something in its viewDidLoad will make a difference.


Example 1

I once made a board game and I had a GameViewController that shows the game screen for a two player game. GameViewController.viewDidLoad does some setup of the game board view and the game model and so on. Then one day I decided to write an AI for the game so that people can play even when they are alone. The game with the AI is a little different from a two player game, so I made a AIGameViewController, which inherits GameViewController.

In AIGameViewController, I must call super.viewDidLoad, or else I have to copy and paste the code in GameViewController.viewDidLoad.


Example 2

There is a library called "Eureka" that allows you to create forms for users to fill in. To use it, you create a new VC that inherits from FormViewController, and then you can start to add rows to the form in viewDidLoad. It is required to call super.viewDidLoad here because FormViewController will, among other things, set up a table view to display the form. Without the table view, your form will not be displayed.

Sweeper
  • 213,210
  • 22
  • 193
  • 313