我知道在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)?
答案 0 :(得分:2)
你快到了!它只是结合你已经生产的东西:
myFunction(myParams: ["blah", "bleh"], callback: { myResult in
_ = self.navigationController?.popViewController(animated: true)
})