Init Super Error

So I'm trying to use an URL as the initialization for class. Here's my script:


  var videoURL : URL
   
    init(videoUrl:URL)
    {     
        self.videoURL = videoUrl     
    }
   
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


I get an error on line 8, "Super.init isn't called on all paths before returning from initializer." I have this in my TableViewCell class so that the controller passes the appropriate URL after some math. Why am I getting this error?

Accepted Answer

I'm afraid that doesn't work Claude. I get an error that says "Nil is incompatable with return type UITableViewCell." What I've ended up doing is giving the "videoURL" variable in my VideoTableViewCell an URL (documents folder), and this in my controller:


override func numberOfSections(in tableView: UITableView) -> Int{
        let videoURLs = try! FileManager.default.contentsOfDirectory(at: docDir, includingPropertiesForKeys: nil)
        return videoURLs.count
    }
   
   
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
   
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let videoURLs = try! FileManager.default.contentsOfDirectory(at: docDir, includingPropertiesForKeys: nil)
        let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell") as! VideoTableViewCell
        cell.videoURL = videoURLs[0]     //set to first part of array for testing
        cell.setDate()
        cell.setTitle()
        cell.setImage()
        return cell
       
    }


I have no issues with this. If there's no URLs no cells are built, and if there are, it initializes one cell for each URL. Now I'm working on passing each part of the array to the appropriate cell. Thanks guys for all of your help.

You're right.


if cell == nil { return nil }


xas not needed and was an error. The line should be deleted

Init Super Error
 
 
Q