Understanding retain cycles in RxSwift

Viewed 681

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?

1 Answers

Yes there is a retain cycle because setEmptyViewShown(_:) is a method which takes self as an implicit first argument.

Better would be something like:

disposeBag.insert(
    showEmptyView.bind(to: emptyView.rx.isHidden),
    showEmptyView.map { !$0 }.bind(to: tableView.rx.isHidden)
)
Related