title: Access properties via subscripting in Swift
body: <p>I have a custom class in Swift and I'd like to use subscripting to access its properties, is this possible?</p>
  
  <p>What I want is something like this:</p>
  
  <pre><code>class User {
      var name: String
      var title: String
  
      subscript(key: String) -&gt; String {
          // Something here
          return // Return the property that matches the key…
      }
  
      init(name: String, title: String) {
          self.name = name
          self.title = title
      }
  }
  
  myUser = User(name: "Bob", title: "Superboss")
  myUser["name"] // "Bob"
  </code></pre>
  
  <p><strong>Update:</strong> The reason why I'm looking for this is that I'm using <a href="https://github.com/groue/GRMustache/blob/master/Guides/view_model.md">GRMustache</a> to render from HTML templates. I'd like to be able to just pass my model object to the GRMustache renderer…</p>
  
  <blockquote>
    <p>GRMustache fetches values with the keyed subscripting objectForKeyedSubscript: method and the Key-Value Coding valueForKey: method. Any compliant object can provide values to templates.</p>
    
    <p><a href="https://github.com/groue/GRMustache/blob/master/Guides/view_model.md#viewmodel-objects">https://github.com/groue/GRMustache/blob/master/Guides/view_model.md#viewmodel-objects</a></p>
  </blockquote>