title: swift remove map overlays
body: <p>I am trying to remove overlays from map.</p>
  <pre><code>func removeMapOverlay() {
      
      var removeOverlays : [AnyObject]! = self.mapView.overlays
      // Above line throws runtime exception
  
      self.mapView.removeOverlays(removeOverlays)
  }
  </code></pre>
  <p><code>self.mapView.overlays</code> are type of <code>AnyObject</code> array.   <code>var overlays: [AnyObject]! { get }</code>.</p>
  <p>So initially I wrote</p>
  <pre><code>var removeOverlays = self.mapView.overlays
  </code></pre>
  <p>It throws <code>EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)</code> exception at this line on runtime.</p>
  <p>So I did type casting for <code>[AnyObject]</code> I don't know it is correct or not but it still gives me same exception at runtime.</p>
  <p><strong>Edit:</strong></p>
  <p>What I did for Objective C code was:</p>
  <pre><code>- (void) removeMapOverlay {
      [self.mapView removeOverlays:[self.mapView overlays]];
      
      NSMutableArray *tempArray = [NSMutableArray arrayWithArray:[self.mapView annotations]];
      if ([tempArray containsObject:[MKUserLocation class]]) {
          [tempArray removeObject:[MKUserLocation class]];
      }
      
      NSArray *annotationArray = [NSArray arrayWithArray:tempArray];
      tempArray = nil;
      [self.mapView removeAnnotations:annotationArray];
  }
  </code></pre>
  <p>I tried to create similar method in Swift. But it throws an exception like I explain above.</p>