Initialize a subclass of UIViewController with Swift?

I am trying to understand how initialization works in Swift with a subclass of UIViewController. I thought the main format was like that, but it throws errors ...

init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!)   {
    //other code
    super.init(nibName: String?, bundle: NSBundle?)
}
+4
source share
2 answers

You pass types, not variables. Instead, you should pass variables.

init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!)  {
    // Initialize variables.

    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
+9
source

Variables should now be initialized before calling super.init

init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!)  {

    // Initialize variables.

    super.init() // as required
}
+4
source

Source: https://habr.com/ru/post/1543032/


All Articles