title: Unable to extract data from Observable Object
body: <p>I'm trying to display data from an observed object.
  <p>
  Initially I tried to keep it simple, to merely display one member of a struct: 'base' (value: "stations"). <br/></p>
  
  <pre><code>struct Sample: Codable {
      let coord: Coord
      let weather: [Weather]
      let base: String
      let main: Main
      let visibility: Int
      let wind: Wind
      let clouds: Clouds
      let dt: Double
  //    let sys: Sys
      let id: Int
      let name: String
  //    let cod: Int
  }
  </code></pre>
  
  <p>I did some defensive coding with '?' but I got the following compiler error: <p></p>
  
  <p><a href="https://i.stack.imgur.com/AKPvT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AKPvT.png" alt="enter image description here"></a></p>
  
  <p><p>
  So I replaced the '?' with '!', knowing that I should have some data. <p></p>
  
  <p><a href="https://i.stack.imgur.com/bHmFP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bHmFP.png" alt="enter image description here"></a>
  <p>
  I find this frustrating, coming from an imperative-paradigm background.
  <br/>
  What am I doing wrong?</p>
  
  <p><p>
  Here's the data dump: 
  
  <blockquote>
    <p>Sample(coord: DataTaskPubTab.Coord(lon: -0.13, lat: 51.51), weather:
    [DataTaskPubTab.Weather(id: 300, main: "Drizzle", description: "light
    intensity drizzle")], base: "stations", main:
    DataTaskPubTab.Main(temp: 280.32, pressure: 1012, humidity: 81,
    tempMin: 279.15, tempMax: 281.15), visibility: 10000, wind:
    DataTaskPubTab.Wind(speed: 4.1, deg: 80), clouds:
    DataTaskPubTab.Clouds(all: 90), dt: 1485789600.0, id: 2643743, name:
    "London")</p>
  </blockquote>
  
  <p><p></p>
  
  <p>Here's the Observable Object: <p></p>
  
  <pre><code>class StandardWeatherReportLoader: ObservableObject {
      @Published var networkMessage: String?
      @Published var hasAlert = false
      @Published var weatherReport: Sample?
      @Published var hasReport = false
  
      func doStandard() {
          let url = EndPoint.weather.path()
          var request = URLRequest(url: EndPoint.weather.path()!)
          request.httpMethod = "GET"
          request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  
          let task = URLSession.shared.dataTask(with: url!) { (data: Data?, _: URLResponse?, error: Error?) -&gt; Void in
              DispatchQueue.main.async {
                  guard error == nil else {
                      self.networkMessage = error?.localizedDescription
                      self.hasAlert = true
                      return
                  }
  
                  do {
                      let decoder = JSONDecoder()
                      decoder.keyDecodingStrategy = .convertFromSnakeCase
                      let result = try decoder.decode(Sample.self, from: data!)
                      self.weatherReport = result
                      self.hasReport = true
                      print(result)
                  } catch let error as NSError {
                      print(error)
                  }
              }
          }
          task.resume()
      }
  }
  </code></pre>
  
  <p><p></p>