title: How do I emit events manually (i.e., make an EventEmitter) using RxSwift?
body: <p>How do I implement an event emitter using RxSwift? (An object that can emit data that is consumed by other objects that are subscribed to it.)</p>
  
  <p>After going through the Rx docs and examples, I feel like a complete idiot and am still extremely confused on how to manually emit events from Observers to Observables. My understanding that we have some Observable that can emit events with data to all Observers that are subscribed to that Observable. However, I have zero idea on how this is actually implemented in Swift.</p>
  
  <p>Here's an example of something I'm trying to implement:</p>
  
  <pre><code>class VendingMachine {
  
      let dispenser = Observable&lt;Drink&gt;
  
      // Notify all subscribed Observers that this machine dispensed a drink.
      func dispenseDrink(item: Drink) {
          dispenser.onNext(item)
      }
  
  }
  </code></pre>
  
  <p>And a second file:</p>
  
  <pre><code>class MachineReporter: Observer {
  
      let dispenser = VendingMachine().dispenser
  
      init() {
          dispenser.subscribe(self)
      }
  
      onNext { drink in
          print("Vending machine dispensed a drink: \(drink)"
      }
  
  }
  </code></pre>
  
  <p>My brain is fried. I'm just going to switch to a specialized library like EmitterKit for now because I'm clearly misunderstanding how this works.</p>
  
  <p>But I need to figure out how Rx works or I will go crazy. Help!</p>