title: Getting string from ViewModel to View in RxSwift
body: <p>I am trying to get a string from <code>ViewModel</code> to <code>View</code> using <code>PublishSubject()</code> but <code>View</code> is not able to get it. Following is my code in <code>ViewModel</code>:</p>
  
  <pre><code>var myImageURL: PublishSubject&lt;String&gt; = PublishSubject&lt;String&gt;()
  
  self.myService.getImage(materialNo: materialNumber).subscribe(
      onNext: { [weak self] imageURL in //I am able to get url here and want to send it to View, following doesn't work
          self?.myImageURL.onNext(imageURL)
          self?.myImageURL.onCompleted()
      },
      onError: { error in },
      onCompleted: { }
  )
  .disposed(by: disposeBag)
  </code></pre>
  
  <p>Code in <code>View</code>:</p>
  
  <pre><code>let disposeBag = DisposeBag()
  
  self.viewModel.myImageURL.subscribe(
      onNext: { 
          print($0 + " image url")
          self.myImageView.af_setImage(withURL: URL(string: $0)!, placeholderImage:UIImage(named: "tool_placeholder"))
      },
      onError: {
          print(String(describing: $0).capitalized)
      }
  )
  .disposed(by: disposeBag)
  </code></pre>
  
  <p>Although viewModel code works fine but I am not able to receive its value in <code>View</code>.</p>
  
  <p><strong>Edit1:</strong>
  Updated code in view with drive:</p>
  
  <pre><code>self.viewModel.myImageURL
          .asObservable()
          .asDriver(onErrorJustReturn: "Error")
          .drive(onNext: {
                          self. myImageView.af_setImage(withURL: URL(string: $0)!, placeholderImage:UIImage(named: "tool_placeholder"))
                      }
              )
          .disposed(by: disposeBag)
  </code></pre>