Emit an event manually in RxSwift

Viewed 13446

I'm a newbie in RxSwift and need a very basic help.
Assump that I have an Observable and subscribe it like this.

 let source: Observable<Void> = Observable.create { [weak self] observer in

        guard let _ = self else {
            observer.on(.Completed)
            return NopDisposable.instance
        }

        observer.on(.Next())

        return AnonymousDisposable {

        }
    }

And the subscribe like this:

 source.subscribeNext { () -> Void in

    }

The question is: how can I emit the event to subscribeNext manually every time I need. This is like rx_tap behavior on UIButton.
I see in the example code has something like this source = button.rx_tap.asObservale(). After that, every time user tap to button, there will emit an event and trigger on subscribeNext(). I also want to have that behavior but in programmatically, not from UI event.

2 Answers
Related