[英]Understanding retain cycles in RxSwift
If I have the following code如果我有以下代码
func handle(showEmptyView: Driver<Bool>) {
showEmptyView
.drive(onNext: setEmptyViewShown)
.disposed(by: disposeBag)
}
func setEmptyViewShown(_ show: Bool) {
tableView.isHidden = !show
emptyView.isHidden = show
}
Is this a retain cycle when I call setEmptyViewShown
because I don't use weak
or unowned
self?当我调用setEmptyViewShown
因为我不使用weak
或unowned
的自我时,这是一个保留周期吗?
Yes there is a retain cycle because setEmptyViewShown(_:)
is a method which takes self
as an implicit first argument.是的,有一个保留周期,因为setEmptyViewShown(_:)
是一种将self
作为隐式第一个参数的方法。
Better would be something like:更好的是:
disposeBag.insert(
showEmptyView.bind(to: emptyView.rx.isHidden),
showEmptyView.map { !$0 }.bind(to: tableView.rx.isHidden)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.