自定义导航返回按钮时, 一般会这样写:
self.navigationController?.popViewController(animated: true)
但是Xcode会发出警告:
原因:
Swift 3 中,所有方法返回值没有捕获到结果,都会出现警告。如果你想告诉编译器这里的警告是没有必要的,你可以在相对应的函数之前添加@discardableResult方法声明。如果你不想使用返回值,您必须显式地告诉编译器通过分配到下划线(或者是强调):
_ = someMethodThatReturnsSomething()
相关链接: Xcode 8 / Swift 3: “Expression of type UIViewController? is unused”warning
解决办法:
方法一:
_ = navigationController?.popViewController(animated: true)
方法二:
self.navigationController!.popViewController(animated: true)