Ismael Ussefatt Ismael Ussefatt - 1 year ago 106
iOS Question

Expression ambiguous when init view

I have this destination view:

class NewItemViewController: UIViewController {

var delegate: AddAnItemDelegate?

init(delegate:AddAnItemDelegate) {
self.delegate = delegate
super.init(nibName: "NewItemViewController", bundle: nil)

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

and this method in the view that i'm pushing from:

func showNewItem() {
let newItem = NewItemViewController(nibName: "NewItemViewController", bundle: nil)
if let navigation = self.navigationController {
navigation.pushViewController(newItem, animated: true)

The problem is i'm getting the ambiguous expression error in the line

let newItem = NewItemViewController(nibName: "NewItemViewController", bundle: nil)

What is the problem?


Answer Source

You need to use one of the two init methods in your NewItemViewController class. Most likely you want:

let newItem = NewItemViewController(delegate: somethingHere)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download