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?

>I have no subclasses (as I understand them)


If your VideoListTableViewController declaration starts with:

class VideoListTableViewController: UITableViewController {

then it is a subclass of UITableViewController.


Similarly, if your VideoListTableViewCell starts with:

class VideoListTableViewCell: UITableViewCell {

then it is a subclass of UITableViewCell.


See the pattern?


Read up on classes and subclasses in The Swift Programming Language guide in Xcode's documentation, or download the ebook. I strongly recommend that you work through it from the very first page, though, regardless of what you think you already understand about Swift.

Got it. I understood it as a class of type UITableViewController, just like when you declare:


let example: String


I should've caught that in the Swift Documentation. So, if everything looks right, what could my error be from?

OK, I've looked at my VideoListTableViewController script when I get my error, and it always happens on line 1 of my displayed script (my third last reply in this thread). On line one it says "Thread 1: breakpoint 1.7." Does that help at all?

Meant to say looked at my controller MORE CAREFULLY!

When you declare a var :


myVar : String, you do not subclass


But if you declare a class:


MyString : String


Then you subclass.


Most likely, in your code, you have somewhere a class declaration:


class VideoListTableViewCell: UITableViewCell

I need to take back what I said. The error occurs at my first variable.


class VideoListTableViewController: UITableViewController {

    let docDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
    var videos = [Video]()


It happens at line 4 in this example. But in this example:


class VideoListTableViewController: UITableViewController {
   
   
    override func viewDidLoad() {
        super.viewDidLoad() 
    }
   
     var videos = [Video]()
   
      
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()      
    }
   
   
    let docDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)


it happens at line 8.

Yah, in the beginning of the file that my TableViewCell is attached to.

Hope you can now connect all the points of this thread and that it solves your problem.


Please tell if the thread is closed by clicking a Correct Answer.

Please provide the exact wording of the error message to which you now refer and the current definition of class Video (even if you think you've already posted any of that info).

Do you get a compiler error or an execution error ?

"goldsdad:

"lease provide the exact wording of the error message to which you now refer"


I get this error in the debugging console when I run everything: "VideoListTableViewController.init(coder : NSCoder) -> VideoListTableViewController?" And this in my VideoListTableViewController class file at the first variable statement OUTSIDE of any functions: "Thread 1: breakpoint 1.7." If all variables are in a function, the message is at the line where the class is defined.


So I get the "Thread 1: breakpoint 1.7" error at line 3 in this example.


class VideoListTableViewController: UITableViewController {


    let docDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
    var videos = [Video]()


In this example it's at line 8.


class VideoListTableViewController: UITableViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
    }

    var videos = [Video]()



    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }


    let docDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)

And it's at line 1 in this case:

class VideoListTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    var videos = [Video]()
}


   override func didReceiveMemoryWarning()
    let docDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
        super.didReceiveMemoryWarning()


    }

goldsdad:

"the current definition of class Video (even if you think you've already posted any of that info)


class Video: NSObject{

    var videoURL: URL

    init?(videoURL: URL)
    {
        self.videoURL = videoURL
    }
}


This Video class is in a separate Swift file just like in the "Start Developing iOS Apps (Swift)" tutorial. Here's the link for the tutorial: https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/DefineYourDataModel.html#//apple_ref/doc/uid/TP40015214-CH20-SW1


Claude31

"Do you get a compiler error or an execution error?"


It's an execution error. There aren't any errors in any script.

At this point, everyone is confused, including you. 😉


Nothing you've described as being an error message is, in fact, an error message.


>> So I get the "Thread 1: breakpoint 1.7" error at line 3 in this example.


This is displayed, in the source file editor, with a translucent green bar highlighting the line of text, when your app stops in the debugger at a breakpoint. It's not an error, just a breakpoint. If you look at the left end of the green bar, you should see a blue icon "pointing" at the line of text. That's a breakpoint icon. To get rid of it (assuming it wasn't your intention to stop here), drag it away from the margin of the text editor until the cursor changes to a "cancel" icon, then let go.


It's easy to set breakpoints by accident if you click in the margin of the editor. You should remove any other breakpoints you've accidentally set.


>> I get this error in the debugging console when I run everything: "VideoListTableViewController.init(coder : NSCoder) -> VideoListTableViewController?"


This isn't an error message either, it's just the name of a method, presumably the method that was executing at the time your app stopped at the breakpoint described above. It's not clear where you're seeing this, but I guess its in the toolbar that appears near the bottom of the Xcode window while the app is running, next to a blue icon, next to something like "Thread 1" with its own blue icon, next to your app name. Right? That's just a display of where you app was executing when it stopped (due to the breakpoint).


Note that, if you stop at a breakpoint, remove the breakpoint (by dragging it out of the editor margin), you can continue execution by clicking the Continue icon (3rd from the left on that same toolbar).


All this is basic Xcode usability stuff. There are a lot of controls and displays in an Xcode window. If you're not sure what they are, you really need to read through the Xcode documentation to get familiar with what's there.

(facepalm) wow.....that simple (facepalm). Well that's embarrassing. I've never even heard of a breakpoint. To quote an awesome movie: "You have much to learn my young padawan." (May the 4th be with you😉) You guys have done so much for me, and have been dealing with my ignorance through so much of this, I can't thank everyone enough.

Deleted. Problem solved.

Updated variable names for clarification.

Init Super Error
 
 
Q