title: How do I show a Image from the web in swiftui?
body: <p>I have been using swiftUI lately to build an application that has a feature to display images downloaded from the web. I tried to make it work but I am having trouble with it right now. I think Maybe there is maybe something wrong with ImageFetcher.swift? Can anyone help me out? Here is my code:</p>
  
  <p><strong>ImageFetcher.swift :</strong></p>
  
  <pre><code>import Foundation
  import Combine
  import SwiftUI
  
  class ImageFetcher: ObservableObject {
  var didChange = PassthroughSubject&lt;Data, Never&gt;()
  
  var data: Data = Data() {
      didSet {
          didChange.send(data)
      }
  }
  
  init(url: String) {
      guard let imageUrl = URL(string: url) else {
          return
      }
  
      URLSession.shared.dataTask(with: imageUrl) { (data, _, _) in
          guard let data = data else { return }
          DispatchQueue.main.async { [weak self] in
              self?.data = data
          }
  
      }.resume()
  }
  }
  </code></pre>
  
  <p><strong>LoadableImageView.swift :</strong></p>
  
  <pre><code>import SwiftUI
  
  struct LoadableImageView: View {
  @ObservedObject var imageFetcher: ImageFetcher
  
  var stateContent: AnyView {
      if let image = UIImage(data: imageFetcher.data) {
          return AnyView(
              Image(uiImage: image).resizable()
          )
      } else {
          return AnyView(
              ActivityIndicator(style: .medium)
          )
      }
  }
  
  init(with urlString: String) {
      imageFetcher = ImageFetcher(url: urlString)
  }
  
  var body: some View {
      HStack {
          stateContent
      }
  }
  }
  
  struct LoadableImageView_Previews : PreviewProvider {
  static var previews: some View {
      LoadableImageView(with: "https://is2-ssl.mzstatic.com/image/thumb/Music113/v4/3d/6d/d0/3d6dd00b-b480-740f-bc6e-e2ca78ff918e/190296882920.jpg/200x200bb.png")
  }
  }
  </code></pre>
  
  <p><strong>ListCellView.swift :</strong></p>
  
  <pre><code>import SwiftUI
  import Foundation
  import AlamofireImage
  import Alamofire
  import Combine
  
  
  struct ListCellView: View {
  
  
  @State var dataSource = DataSource()
  var viewModel: RestrauntListViewModel
  var imageLoader = ImageLoader()
  
  var body: some View {
      HStack {
  
          LoadableImageView(with: viewModel.imageURL.absoluteString)
  
          Spacer()
          VStack(alignment: .center, spacing: 1.0) {
              Text(viewModel.name)
  
              Image(dataSource.configureRatings(rating: viewModel.rating))
              Text("\(viewModel.formattedDistance) miles")
          }
          .padding(.all)
          Spacer()
      }
  }
  }
  struct ListCellView_Previews: PreviewProvider {
  
  static var previews: some View {
      ListCellView(viewModel: RestrauntListViewModel(name: "in 3nout", imageURL: URL(string: "https://s3-media2.fl.yelpcdn.com/bphoto/FNYCY1myO6qlqXLTpGPyIA/o.jpg")!, distance: 4.94578764532, id: "34526434", rating: 4))
  }
  }
  </code></pre>