Ismael Ussefatt Ismael Ussefatt - 1 month ago 20
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?

thanks

Answer

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

let newItem = NewItemViewController(delegate: somethingHere)