Sausage Modulation Matrix Sausage Modulation Matrix -5 years ago 2593
Swift Question

Xcode 8 / Swift 3: "Expression of type UIViewController? is unused" warning

I've got the following function which compiled cleanly previously but generates a warning with Xcode 8.

func exitViewController()
navigationController?.popViewController(animated: true)

"Expression of type "UIViewController?" is unused".

Why is it saying this and is there a way to remove it?

The code executes as expected.

Answer Source

popViewController(animated:) returns UIViewController?, and the compiler is giving that warning since you aren't capturing the value. The solution is to use let with no name:

let _ = navigationController?.popViewController(animated: true)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download