title: When is mapView:viewForAnnotation called in Swift?
body: <p>According to <a href="https://stackoverflow.com/questions/9442830/in-which-case-that-mapviewviewforannotation-will-be-called">this post</a> whenever you call <code>addAnnotation</code> method,  <code>mapView:viewForAnnotation</code> gets called</p>
  
  <p>However the following code called <code>mapView:viewForAnnotation</code> only once. I have several annotations, but "view called" was only printed once. I guess this has something to do with the thread?</p>
  
  <pre><code>import UIKit
  import MapKit
  import CoreLocation
  
  class ViewController: UIViewController, UITextFieldDelegate, MKMapViewDelegate, CLLocationManagerDelegate {
  
      @IBOutlet var searchtext: UITextField!
      @IBOutlet var map: MKMapView!
  
      var locationManager = CLLocationManager()
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          self.searchtext.delegate = self
  
          locationManager.delegate = self
          self.map.delegate = self
  
          locationManager.desiredAccuracy = kCLLocationAccuracyBest
          locationManager.requestWhenInUseAuthorization()
          locationManager.startUpdatingLocation()
      }
  
      func textFieldDidBeginEditing(textField: UITextField!) {    //delegate method
          var allAnnotations = self.map.annotations
          self.map.removeAnnotations(allAnnotations)
      }
  
      func textFieldShouldReturn(textField: UITextField!) -&gt;Bool {
          textField.resignFirstResponder()
  
          //...
  
          let session = NSURLSession.sharedSession()
  
          var task = session.dataTaskWithURL(url!, completionHandler: { (date, response, error) -&gt; Void in
              if (error != nil) {
                  println(error)
              }else {
                  var placenum = 0
                  //placenum is to see if all the places are in the visible rect. If so I will use showAnnotations to zoom (in) to the best-fitted view show them. If not, I will only show these in the visible rect
                  for place in places {
                      //...
                      if (regionContains(self.map.region, coordinate)) {
                          placenum = placenum+1
                      }
                      self.map.addAnnotation(annotation)
                  }
  
                  if (placenum==places.count) {
                      self.map.showAnnotations(self.map.annotations, animated: true)
                  }
              }
  
          })
  
          task.resume()
  
          return true
      }
  
      func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
  
          //...
          self.map.setRegion(region, animated: false)
  
          locationManager.stopUpdatingLocation()
      }
  
      func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -&gt; MKAnnotationView! {
          println("view called")
  
          return nil
      }
  </code></pre>