title: Create classes and structs to represent JSON objects in Swift
body: <p>I'm attempting to create classes that correspond to JSON data retrieved in Swift. For nested objects, is it suitable to represent them via structs rather than separate classes? Or should these simply be treated as dictionary objects? So for example below is some JSON:</p>
  
  <pre><code>{
    prop1: value1,
    prop2: {
      subprop1: subvalue1,
      subprop2: subvalue2
    }
  }
  </code></pre>
  
  <p>What would be the best way to represent the nested <code>prop2</code> object in a Swift class? I'm currently doing so using structs as follows:</p>
  
  <pre><code>class MyClass {
    struct prop2 {
      var subprop1: AnyObject?
      var subprop2: AnyObject?
    }
  
    var prop1: AnyObject?
  }
  </code></pre>
  
  <p>This method becomes a bit cumbersome, however, when there are deeply nested objects so not sure how best to handle those cases.</p>
  
  <p>I'll also add that I have no problem serializing the data into NSDictonary objects like so:</p>
  
  <pre><code>if let details: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &amp;err) as? NSDictionary { }
  </code></pre>
  
  <p>However, I'm trying to take this one step further and map the dictionary's properties to their respective class variables/structs in Swift.</p>