title: How to access deeply nested dictionaries in Swift
body: <p>I have a pretty complex data structure in my app, which I need to manipulate.  I am trying to keep track of how many types of bugs a player has in thier garden. There are ten types of bugs, each with ten patterns, each pattern having ten colors. So there are 1000 unique bugs possible, and I want to track how many of each of these types the player has. The nested dictionary looks like:</p>
  
  <pre><code>var colorsDict: [String : Int]
  var patternsDict: [String : Any] // [String : colorsDict]
  var bugsDict: [String : Any] // [String : patternsDict]
  </code></pre>
  
  <p>I do not get any errors or complaints with this syntax.</p>
  
  <p>When I want to increment the player's bug collection though, doing this:</p>
  
  <pre><code>bugs["ladybug"]["spotted"]["red"]++
  </code></pre>
  
  <p>I get this error:  <strong>String is not convertible to 'DictionaryIndex&lt; String, Any >'</strong>  with the error's carrot under the first string.</p>
  
  <p>Another similar post suggested using "as Any?" in the code, but the OP of that post only had a dictionary one deep so could do that easily with: dict["string"] as Any? ...</p>
  
  <p>I am not sure how to do this with a multilevel dictionary. Any help would be appreciated.</p>