[英]Neither weak nor strong or unowned will do during self dismissal?
Is this a valid pattern to avoid being retained after the dismissal? 这是避免被解雇后保留的有效模式吗?
@objc func backButtonTapped() {
var s: SiteViewController! = self
navigationController!.popToRootViewController(animated: true, completion: {
s.dismissCompletion()
s = nil // break the strong reference to self
})
}
You can just use self
in the closure. 您可以只在封闭中使用
self
。 Once control returns from the closure the reference to self
will be released. 一旦控件从关闭返回,对
self
的引用将被释放。
If you did want to use s
there is no reason to declare it as an implicitly unwrapped optional. 如果确实要使用
s
,则没有理由将其声明为隐式展开的可选。 You could just say var s = self
你可以说
var s = self
This closure should release s
right once it is executed. 此次关闭应该释放
s
一旦执行权。 I think you can place self
there without worries 我想你可以
self
在这里
You can do following to avoid retention, 您可以执行以下操作以避免保留,
@objc func backButtonTapped() {
navigationController!.popToRootViewController(animated: true, completion: { [weak self] in
if let strongSelf: SiteViewController = self {
strongSelf.dismissCompletion()
}
})
}
This will make sure there won't be any retention. 这样可以确保不会有任何保留。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.