title: How to access property or method from a variable?
body: <p>Is it possible to access a method or property using a variable as the name of the method or property in Swift?</p>
  
  <p>In PHP you can use $object->{$variable}. For example</p>
  
  <pre><code>class Object {
    public $first_name;
  }
  
  $object = new Object();
  $object-&gt;first_name = 'John Doe';
  
  $variable = 'first_name';
  $first_name = $object-&gt;{$variable}; // Here we can encapsulate the variable in {} to get the value first_name
  print($first_name);
  // Outputs "John Doe"
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here is the actual code I'm working with:</p>
  
  <pre><code>class Punchlist {
      var nid: String?
      var title: String?
  
      init(nid: String) {
  
          let (result, err) = SD.executeQuery("SELECT * FROM punchlists WHERE nid = \(nid)")
          if err != nil {
              println("Error")
          }
          else {
              let keys = self.getKeys()  // Get a list of all the class properties (in this case only returns array containing "nid" and "title")
              for row in result {  // Loop through each row of the query
                  for field in keys {  // Loop through each property ("nid" and "title")
                      // field = "nid" or "title"
                      if let value: String = row[field]?.asString() {
                          // value = value pulled from column "nid" or "title" for this row
                          self.field = value  //&lt;---!! Error: 'Punchlist' does not have a member named 'field'
                      }
                  }
              }
          }
      }
  
      //  Returns array of all class properties
      func getKeys() -&gt; Array&lt;String&gt; {
          let mirror = reflect(self)
          var keys = [String]()
          for i in 0..&lt;mirror.count {
              let (name,_) = mirror[i]
              keys.append(name)
          }
  
          return keys
      }
  }
  </code></pre>