Step into Swift logo

Result of call to subscribe(onNext: onError: onCompleted: onDisposed:) is unused

Rx Warning: Result of call to subscription is unused

RxSwift: Result of call to subscribe(onNext: onError: onCompleted: onDisposed:) is unused - warning

  • The solution is simply to add the subscription to a DisposeBag by adding .disposed(by: disposeBag) at the end of the subscription.
viewController
            .actions
            .subscribe(onNext: { [unowned self] actions in
                switch actions {
                case let .showLogin():
                    self.showLogin()
                }
            })
            .disposed(by: disposeBag)
  • This will cancel and dispose of the subscription whenever the view controller is released.
  • Prevents wasting resources but also avoids unexpected events or other side effects when subscriptions are not disposed.

< All Posts