-2

While Running this programm I am facing the error:

'super.init' isn't called on all paths before returning from initializer

I don't know why it is causing interuption in my program. Can somebody help me?

I am using Swift 4.0

import UIKit

class Macbook: UIViewController {
    let myColor:String
    let myBuildType:Int

    init(color:String,BuildType:Int) {
        self.myColor = color
        self.myBuildType = BuildType
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

enter image description here

  • 1
    Just what it says. At the end of your `init` you must call `super.init` in some form. – matt Aug 29 '18 at 04:10
  • i had used Super.init() in the blockof init() but still i am having the error , it says "Must call a designated initializer of the superclass 'UIViewController'" – Gurpal Rajput Aug 29 '18 at 04:14
  • 1
    Please [search on the error](https://stackoverflow.com/search?q=%27super.init%27+isn%27t+called+on+all+paths+before+returning+from+initializer) and please read the [Intialization](https://docs.swift.org/swift-book/LanguageGuide/Initialization.html) chapter of the Swift book. – rmaddy Aug 29 '18 at 04:18

1 Answers1

0

You can try super.init(nibName: nil, bundle: nil) in init.

rmaddy
  • 314,917
  • 42
  • 532
  • 579