Swift Dictionary of Arrays <p>I am making an app that has different game modes, and each game mode has a few scores. I am trying to store all the scores in a dictionary of arrays, where the dictionary's key is a game's id (a String), and the associated array has the list of scores for that game mode. But when I try to initialize the arrays' values to random values, Swift breaks, giving me the error below. This chunk of code will break in a playground. What am I doing wrong?</p> <pre><code>let modes = ["mode1", "mode2", "mode3"] var dict = Dictionary&lt;String, [Int]&gt;() for mode in modes { dict[mode] = Array&lt;Int&gt;() for j in 1...5 { dict[mode]?.append(j) let array:[Int] = dict[mode]! let value:Int = array[j] //breaks here } } </code></pre> <p>ERROR:</p> <pre><code>Execution was interrupted, reason: EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP, subcode=0x0). </code></pre>