title: Swift Insert Element At Specific Index
body: <p>I'm doing a project that has an online streaming of music.</p>
  
  <ol>
  <li><p>I have an array of object called <strong>Song</strong> - Each song in that array of Song has a URL from SoundCloud.</p></li>
  <li><p>Fast enumerate each song and then call the SoundCloud <strong>Resolve API</strong> to get the direct stream URL of each song. And store each direct url into an Array and load to my Player.</p></li>
  </ol>
  
  <p>This seems to be really easy, but the #2 step is asynchronous and so each direct URL can be stored to a wrong index of array. I'm thinking to use the <strong>Insert AtIndex</strong> instead of <strong>append</strong> so I made a sample code in <strong>Playground</strong> cause all of my ideas to make the storing of direct URL retain its order, didn't work successfully.</p>
  
  <pre><code>var myArray = [String?]()
  
  func insertElementAtIndex(element: String?, index: Int) {
  
      if myArray.count == 0 {
          for _ in 0...index {
              myArray.append("")
          }
      }
  
      myArray.insert(element, atIndex: index)
  }
  
  insertElementAtIndex("HELLO", index: 2)
  insertElementAtIndex("WORLD", index: 5)
  </code></pre>
  
  <p>My idea is in this playground codes, it produces an error of course, and finally, my question would be: what's the right way to use this <strong>insert atIndex</strong> ?</p>