title: RxSwift Using Variables Correctly
body: <p>I am trying to convert a project to use RxSwift and MVVM. I have a service that syncs a list of data from Parse on every app launch and I basically want to make sure I am taking the correct approach.</p>
  
  <p>What I have done is made a Variable subject and then allow my models to listen to this.
  ParseService:</p>
  
  <pre><code>let rx_parseMushrooms = Variable&lt;[ParseMushroom]&gt;([])
  </code></pre>
  
  <p>MushroomLibraryModel:</p>
  
  <pre><code>_ = parseService.rx_parseMushrooms
      .asObservable()
      .map { (parseMushrooms:[ParseMushroom]) -&gt; [Mushroom] in
          let mushrooms = parseMushrooms.map { (parseMushroom:ParseMushroom) -&gt; Mushroom in
              let mushroom = Mapper&lt;Mushroom&gt;().map(parseMushroom.dictionaryWithValuesForKeys(parseMushroom.allKeys()))
              return mushroom!
          }
  
          return mushrooms
      }
      .subscribeNext({ (mushrooms:[Mushroom]) -&gt; Void in
          self.mushrooms = mushrooms
          print(mushrooms)
      })
  </code></pre>
  
  <p>I do the same for expressing the sync state.</p>
  
  <p>ParseService:</p>
  
  <pre><code>struct SyncState {
      enum State {
          case Unsynced, ConnectingToServer, SyncingInfo, FetchingImageList, SyncingImages, SyncComplete, SyncCompleteWithError
      }
  
      var infoToSync = 0
      var imagesToSync = 0
      var imagesSynced = 0
  
      var state = State.Unsynced
  }
  
  let rx_syncState = Variable(SyncState())
  </code></pre>
  
  <p>I then update the variable a la</p>
  
  <pre><code>self.rx_syncState.value = self.syncState
  </code></pre>
  
  <p>SyncViewModel:</p>
  
  <pre><code>_ = parseService.rx_syncState
       .asObservable()
       .subscribeNext { [weak self] (syncState:ParseService.SyncState) -&gt; Void in
            switch syncState.state {
                //show stuff based on state struct
            }
        }
  </code></pre>
  
  <p>Anyways, I would greatly appreciate if someone can tell me if this is a good way of going about it or if I am misusing RxSwift (and guide me on how I should be doing this).</p>
  
  <p>Cheers! </p>