title: Simultaneous memory access error while inserting element in array
body: <p>I'm getting Simultaneous memory access error in my below method. Can anyone advice how should I modify it to remove this error and keep the functionality intact.</p>
  
  <pre><code>func add(myItem:String, atIndex index:Int){
  
      if self.myItems!.count-1 &gt; index {
          self.myItems?.insert(myItem, at: index)
      }
      else{
  
          while index &gt; self.myItems!.count {
              //getting error in this insert statement below
              self.myItems?.insert(myItemPlaceHolder, at: self.myItems!.count)
          }
  
          self.myItems?.append(myItem)
      }
  }
  </code></pre>
  
  <p>This is how the array is defined <code>var myItems : [String]?</code></p>
  
  <p>Any advice is appreciated.</p>