title: MKMapView add annotations in background thread
body: <p>When the map is moved the <code>MKMapView</code> invokes the delegate function below. Due to the nature of our application we add new vehicles to the map in a separate thread. We have noticed that there is a chance that the application will crash when this code is executed. The error occurs on line 5 in the for loop. Could anyone please explain why the loop is returning nil annotations?</p>
  
  <pre><code>func regionDidChange(mapView: MKMapView, animated: Bool) {
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
          var vehiclesToAdd = [VehicleAnnotation]()
  
          for (var i = 0; i &lt; self.mapView.annotations.count; i++) {
              if (self.mapView.annotations[i].isKindOfClass(VehicleAnnotation)) {
                  let vehicleAnnotation: VehicleAnnotation! = self.mapView.annotations[i] as VehicleAnnotation
  
                  if (!MKMapRectContainsPoint(mapView.visibleMapRect, MKMapPointForCoordinate(vehicleAnnotation.coordinate))) {
                      vehiclesToAdd.append(vehicleAnnotation)
                  }
              }
          }
  
          dispatch_async(dispatch_get_main_queue()) {
              self.mapView.addAnnotations(vehiclesToAdd)
          }
      })
  }
  </code></pre>
  
  <p>Any ideas why this is happening?</p>