0

I am trying to retrieve information from a NSDictionary using init. I am receiving the error "Must call a designated initializer of the superclass 'UIViewController" on the super.init() line

Here is my code:

init(dictionary: NSDictionary) {
    let title = dictionary["title"] as? String
    let poster = dictionary["poster_path"] as! String
    let baseUrl = "http://image.tmdb.org/t/p/w500"
    let imageUrl = URL(string: baseUrl + poster)
    detailsTitle.text = title
    detailsImage.setImageWith(imageUrl!)
    super.init()
}

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

}

}

I have tried the following:

super.init(coder: )
super.int(coder: aDecoder)
super.init(dictionary: NSDictionary)
super.init(coder: NSCoder)
super.init(coder: aDecoder: NSCoder)
super.init(coder: dictionary: NSDictionary)
JSharpp
  • 459
  • 1
  • 9
  • 21
  • FYI - you should not be using `NSDictionary`. Use a proper Swift dictionary. And your should not use `+` to build a URL string. And be careful with your use of `!`. Those are crashes waiting to happen. – rmaddy Oct 03 '18 at 17:37
  • It is the only way I know how to use JSONSerialization with an api. The information becomes stored in a NSDictionary. https://developer.apple.com/documentation/foundation/jsonserialization – JSharpp Oct 03 '18 at 17:49
  • `JSONSerialization` works with Swift arrays and dictionaries. Just use the proper cast. – rmaddy Oct 03 '18 at 17:51

0 Answers0