Creating an IBOutlet in Swift results in a class is not constructive with () '

My code was compiled before upgrading to beta 4, however I think they changed something using IBOutlets.

Old syntax:

@IBOutlet var tableView: UITableView

New syntax:

@IBOutlet weak var tableView: UITableView!

This is the default code generated by Xcode when I drag and drop ctrl from my xib file to the class file.

However, with this new syntax, I cannot create an instance of my class. Take the following example:

class TestViewController: UIViewController {
    @IBOutlet weak var tableView: UITableView!
}

Then if I try to do either

var controller = TestViewController(nibName: nil, bundle: nil)

or

var controller = TestViewController()

I get an error message:

TestViewController is not constructive with ()

What is the correct way to instantiate my controller? The only way that currently works for me is to make the routes optional, but I would prefer not to.

+4
2

.

@IBOutlet var tableView: UITableView?

, , .

+1

init :

init()
{
    super.init(nibName: nil, bundle: nil)
}

, .

0

All Articles