I'm new to RxSwift and got confused when reading blogs about it.
Is this a proper way to create a button in a customized view?
let disposeBag = DisposeBag()
lazy var followButton: UIButton = {
let btn = UIButton(frame: .zero)
btn.rx.tap.subscribe(onNext: { [weak self] in
// do something when the button is tapped
}).disposed(by: disposeBag) // this line
return btn
}()
Is it necessary to use disposed(by: DisposeBag) as long as the button is subscribed(observed)?
Update
lazy var followButton: UIButton = {
let btn = UIButton(frame: .zero)
btn.rx.tap.subscribe(onNext: { [weak self] in
// do something when the button is tapped
})
// a warning says
// Result of call to 'subscribe(onNext:onError:onCompleted:onDisposed:)' is unused
return btn
}()
The warning seems to imply the api is designed to connect with another method like disposed.
What method should be used here if we don't need disposed?
Or just _ = btn.rx.tap.subscribe...?