作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我知道在 swift 3 中是这样的:
navigationController?.popViewController(animated: true)
会产生这个警告:
"Expression of type "UIViewController?" is unused"
而且我知道消除此警告的推荐方法是执行以下操作:
_ = navigationController?.popViewController(animated: true)
但是当它在闭包中时:
myFunction(myParams: ["blah", "bleh"], callback: { myResult in
_ = navigationController?.popViewController(animated: true)
})
我收到这个错误:
Implicit use of 'self' in closure; use 'self.' to make capture semantics explicit
如果我这样做:
myFunction(myParams: ["blah", "bleh"], callback: { myResult in
self.navigationController?.popViewController(animated: true)
})
我又收到警告了:
"Expression of type "UIViewController?" is unused"
如何在没有警告和错误的闭包内使用 navigationController?.popViewController(animated: true)?
最佳答案
你快到了!它只是结合您已经生产的产品:
myFunction(myParams: ["blah", "bleh"], callback: { myResult in
_ = self.navigationController?.popViewController(animated: true)
})
关于swift - 我如何使用 navigationController?.popViewController(动画 : true) inside of a closure with no warnings and errors?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41042898/
我是一名优秀的程序员,十分优秀!