title: Using a generic value for the model (vs a static model.self) to be parsed with JSONDecoder
body: <p><strong>Scenario:</strong> I want to use a common function to access various endpoints.  So I'm trying to create boilerplate code to process various data models (struct.self) with their associated URLs.</p>
  <p>Here are a couple of models that <em>share a common</em> URLSession + decode code:</p>
  <pre><code>// MARK: - Region
  struct Region: Codable {
      let country: String
      let subregions: [String]
  }
  
  
  // MARK: - SubRegion
  struct SubRegion: Codable {
      let country: String
      let subregion: Sub
      let data: [Datum]
  }
  </code></pre>
  <p>Here's one data vector (<code>Region</code>) that contains a URL with its associated data model:</p>
  <pre><code>struct URLDataModel {
      var url = URL(string: &quot;https://disease.sh/v3/covid-19/apple/countries/Canada&quot;)
      var dataModel: Any = Region.self
  }
  </code></pre>
  <p>The following is the entire class that contains the shared <code>getRegionList()</code> using the <code>URLDataModel</code> struct:</p>
  <pre><code>class CountryRegionListModelView: ObservableObject {
      @Published var countryRegionList = [String]()
  
      // Data Persistence:
      var cancellables: Set&lt;AnyCancellable&gt; = []
  
      // TODO: --- Get Region tag ---
      func getRegionList(urlDataModel: URLDataModel) {
          // MARK: - Region
  
          struct Country: Codable {
              let countries: [String]
          }
          struct Region: Codable {
              let country: String
              let subregions: [String]
          }
          print(&quot;url: &quot;, urlDataModel.url)
  
          let remoteDataPublisher = URLSession.shared.dataTaskPublisher(for: urlDataModel.url!)
              // the dataTaskPublisher output combination is (data: Data, response: URLResponse)
              .map(\.data)
              .receive(on: DispatchQueue.main)
              .print(&quot;Hello Data&quot;)
              .decode(type: urlDataModel.dataModel, decoder: JSONDecoder())
  
          remoteDataPublisher
              .sink(receiveCompletion: { completion in
                  switch completion {
                  case .finished:
                      break
                  case let .failure(anError):
                      Swift.print(&quot;received error: &quot;, anError)
                  }
              }, receiveValue: { someValue in
                  self.countryRegionList = someValue.subregions
                  print(self.countryRegionList)
  
              }).store(in: &amp;cancellables)
      }
  }
  </code></pre>
  <p>
  <b>Problem:</b> I don't know how to make the JSON decoder work with a <em>variable</em> model type <b>'model'.self</b>.
  <p>Should I use generics?  <br/>
  How would that work?