Nina Nina - 4 months ago 81
iOS Question

Expression of type [UIViewController]? unused

I just migrated to Xcode 8.0 and from Swift 2.2 to Swift 3.0.

I've got a UITableViewController with this method:

@IBAction func cancelToLastLevelNavigationController(_ segue:UIStoryboardSegue) {

// go back to last table view controller
let count = self.navigationController?.viewControllers.count
self.navigationController?.popToViewController((self.navigationController?.viewControllers[count! - 1])!, animated: true)

Now XCode is telling me "Expression of type [UIViewController]? unused" and points to the first "p" of "popToViewController".

Why? The method still does what it should do.


Write it like this:

_ = self.navigationController?.popToViewController...

Your code works exactly the same, and the warning goes away.