title: CodingKey not found from a different struct during decoding
body: <p>I am trying to use a parsed date string (<code>dateString</code>) from the <code>Datum</code> struct to build a new Date object in the <code>AzimuthAtDate</code> class...</p>
  <pre><code>{
      &quot;11&quot;: [{
          &quot;name&quot;: &quot;Sun&quot;,
          &quot;date&quot;: &quot;2021-01-26&quot;,
          &quot;rising&quot;: [{
              &quot;coord&quot;: &quot;113.6681&quot;,
              &quot;hour&quot;: &quot;07:16&quot;
          }],
          &quot;transit-sup&quot;: [{
              &quot;coord&quot;: &quot;32.4711&quot;,
              &quot;hour&quot;: &quot;12:16&quot;
          }],
          &quot;setting&quot;: [{
              &quot;coord&quot;: &quot;246.4743&quot;,
              &quot;hour&quot;: &quot;17:17&quot;
          }]
      }]
  }
  </code></pre>
  <pre><code>struct Datum: Codable, CustomStringConvertible {
  
      let name: String
      let dateString: String
      let isoDate: Date?
      let rising: [AzimuthAtDate]
      let transit: [ElevationAtDate]
      let setting: [AzimuthAtDate]
      
      enum CodingKeys: String, CodingKey {
          case name
          case dateString = &quot;date&quot;
          case isoDate
          case rising = &quot;rising&quot;
          case transit = &quot;transit-sup&quot;
          case setting = &quot;setting&quot;
      }
  
      init(from decoder: Decoder) throws {
          let con = try decoder.container(keyedBy: CodingKeys.self)
          self.name = try con.decode(String.self, forKey: .name)
          self.dateString = try con.decode(String.self, forKey: .dateString)
          self.isoDate = try con.decode(Date.self, forKey: .dateString)
          self.rising = decodeAzimuthAtDate(decoder: decoder, key: .rising)
          self.transit = decodeElevationAtDate(decoder: decoder, key: .transit)
          self.setting = decodeAzimuthAtDate(decoder: decoder, key: .setting)
      }
  }
  
  </code></pre>
  <pre><code>class CoordHour: Codable {
      let coord: String
      let hour: String
      var isoDate: Date?
      init(coord: String, hour: String, isoDate: Date?) {
          self.coord = coord
          self.hour = hour
          self.isoDate = isoDate
      }
  }
  </code></pre>
  <p>But in trying to access a key from <code>Datum.CodingKeys</code> from within <code>AzimuthAtDate</code>, <code>datumContainer</code> has no keys. And so I get an error like this:
  <code>keyNotFound(CodingKeys(stringValue: &quot;date&quot;, intValue: nil) ... debugDescription: &quot;No value associated with key CodingKeys(stringValue: \&quot;date\&quot;, intValue: nil) (\&quot;date\&quot;).&quot;, underlyingError: nil))</code></p>
  <pre><code>class AzimuthAtDate: CoordHour {
      required init(from decoder: Decoder) throws {
          let coordHourContainer = try decoder.container(keyedBy: CoordHour.CodingKeys.self)
          let coord = try coordHourContainer.decode(String.self, forKey: .coord)
          let hour = try coordHourContainer.decode(String.self, forKey: .hour)
          
          print(&quot;coord:\(coord) - hour:\(hour)&quot;) // prints correct info
          
          let datumContainer = try decoder.container(keyedBy: Datum.CodingKeys.self)
  
          print(&quot;datumContainer keys:\(datumContainer.allKeys)&quot;) // shows []
          
          let dateString = try datumContainer.decode(String.self, forKey: .dateString)
          print(&quot;dateString:\(dateString)&quot;)
          
          let currentTZ = TimeZone.currentOffsetFromUTCString
          let isoDateString = &quot;\(dateString)T\(hour)\(currentTZ)&quot;
          let isoDate = DateFormatter.Iso.date(from: isoDateString)
          
          super.init(coord: coord, hour: hour, isoDate: isoDate)
      }
  }
  </code></pre>
  <p>In the <code>AzimuthAtDate</code> class, how can I get access to <code>Datum.dateString</code> key so I can use its value to form <code>isoDate</code>?</p>
  <pre><code>func decodeAzimuthAtDate(decoder: Decoder, key: Datum.CodingKeys) -&gt; [AzimuthAtDate] {
      var result = [AzimuthAtDate]()
      do {
          let con = try decoder.container(keyedBy: Datum.CodingKeys.self)
          if let az = try con.decode([AzimuthAtDate]?.self, forKey: key)?.first {
              result.append(az)
          }
      } catch let error {
          print(error)
      }
      return result
  }
  </code></pre>