title: Is it possible to access a struct member using a variable in Swift 4?
body: <p>I've got a list of instances of the following <code>struct</code> called <code>payment_list</code>:</p>
  
  <pre><code>struct Payment: Codable {
  
      let id: Int
      let payment_hash: String
      let destination: String
      let msatoshi: Int
      let timestamp: Int
      let created_at: Int
      let status: String
  
      enum PaymentKeys: String, CodingKey {
          case payments
      }
  }
  </code></pre>
  
  <p>I can access the members of each <code>struct</code> instance in the list in the following manner:</p>
  
  <pre><code>print(payment_list[0].id)        // 1 
  print(payment_list[0].timestamp) // 1517083775
  </code></pre>
  
  <p>Is it possible to access those <code>struct</code> instance members using a variable to determine which member is being accessed? Something along the lines of:</p>
  
  <pre><code>var column = "id"
  print(payment_list[0][column]) // 1
  </code></pre>
  
  <p>I've read about people using <code>NSObject</code> and <code>value(forKey key: String)</code>, but this is a <code>struct</code> so it can't inherit from <code>NSObject</code>. If it <em>was</em> an object I think it would look something like this:</p>
  
  <pre><code>var column = "id"
  print(payment_list[0].value(forKey key: column)) // 1
  </code></pre>
  
  <p>Is this type of thing possible with <code>struct</code>?</p>