title: Rendering multiple polylines on MapView
body: <p>I have two sets of coordinates and trying to draw polylines on map view. I'm able to draw a polyline with one set of coordinates but I couldn't able to draw two polylines.</p>
  
  <p>Below is the code...</p>
  
  <pre><code>func drawRouteOnMap()
  {
      var centerCoordinate : CLLocationCoordinate2D = CLLocationCoordinate2DMake(icRouteLat[0], icRouteLong[0])
      let span = MKCoordinateSpanMake(0.001, 0.001)
      var centerPosition = MKCoordinateRegionMake(centerCoordinate, span)
      mapView.setRegion(centerPosition,animated:true)
      self.mapView.mapType = MKMapType.Hybrid
  
      routePointer = "one";
      // first route line
      //----------able to draw polyline with this set of coordinates
      for i in 0..&lt;routeLat.count-1
      {
          var fromCoordinate :CLLocation = CLLocation(latitude: routeLat[i], longitude: routeLong[i])
          var toCoordinate   :CLLocation = CLLocation(latitude: routeLat[i+1], longitude: routeLong[i+1])
          var locations = [fromCoordinate, toCoordinate];
          var coordinates = locations.map({(location: CLLocation) -&gt; CLLocationCoordinate2D in return location.coordinate});
          var polyLine = MKPolyline(coordinates: &amp;coordinates, count: locations.count);
          mapView.addOverlay(polyLine);
      }
  
      routePointer = "second";
      // IC route line
      //------Polyline for this set of coordinates doesn't appear on map view
      for j in 0..&lt;icRouteLat.count-1
      {
          var fromCoordinateIC :CLLocation = CLLocation(latitude: icRouteLat[j], longitude: icRouteLat[j])
          var toCoordinateIC :CLLocation = CLLocation(latitude: icRouteLong[j+1], longitude: icRouteLong[j+1])
          var locationsIC = [fromCoordinateIC, toCoordinateIC];
          var coordinatesIC = locationsIC.map({(location: CLLocation) -&gt; CLLocationCoordinate2D in return location.coordinate});
          var polyLineIC = MKPolyline(coordinates: &amp;coordinatesIC, count: locationsIC.count);
          mapView.addOverlay(polyLineIC);
      }
  }
  
  func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -&gt; MKOverlayRenderer! {
      let route: MKPolyline = overlay as MKPolyline
      let routeRenderer = MKPolylineRenderer(polyline:route)
      routeRenderer.lineWidth = 3.0
      if routePointer == "one"
      {
          routeRenderer.strokeColor = UIColor(red: 240.0/255.0, green: 68.0/255.0, blue: 0.0/255.0, alpha: 1);
      }
      else if routePointer == "second"
      {
          routeRenderer.strokeColor = UIColor(red: 45.0/255.0, green: 200.0/255.0, blue: 0.0/255.0, alpha: 1);
      }
      return routeRenderer
  }
  </code></pre>
  
  <p>The arrays <code>routeLat[], routeLong[]</code> and <code>icRouteLat[] and icRouteLong[]</code> are two set of coordinates.</p>
  
  <p>Is there anything I'm missing out here? Or is this the right way to implement?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Updated code based on the suggestions...</p>
  
  <pre><code>func drawRouteOnMap()
  {
      var centerCoordinate : CLLocationCoordinate2D = CLLocationCoordinate2DMake(icRouteLat[0], icRouteLong[0])
      let span = MKCoordinateSpanMake(0.001, 0.001)
      var centerPosition = MKCoordinateRegionMake(centerCoordinate, span)
      mapView.setRegion(centerPosition,animated:true)
      self.mapView.mapType = MKMapType.Hybrid
      var polyLine: MKPolyline!
      var polyLineIC: MKPolyline!
  
      // first route line
      for i in 0..&lt;routeLat.count-1
      {
          var fromCoordinate :CLLocation = CLLocation(latitude: routeLat[i], longitude: routeLong[i])
          var toCoordinate   :CLLocation = CLLocation(latitude: routeLat[i+1], longitude: routeLong[i+1])
          var locations = [fromCoordinate, toCoordinate];
          var coordinates = locations.map({(location: CLLocation) -&gt; CLLocationCoordinate2D in return location.coordinate});
          polyLine = MKPolyline(coordinates: &amp;coordinates, count: locations.count);
          polyLine.title = "one";
          mapView.addOverlay(polyLine);
      }
  
      // IC route line
      for j in 0..&lt;icRouteLat.count-1
      {
          var fromCoordinateIC :CLLocation = CLLocation(latitude: icRouteLat[j], longitude: icRouteLong[j])
          var toCoordinateIC :CLLocation = CLLocation(latitude: icRouteLat[j+1], longitude: icRouteLong[j+1])
          var locationsIC = [fromCoordinateIC, toCoordinateIC];
          var coordinatesIC = locationsIC.map({(location: CLLocation) -&gt; CLLocationCoordinate2D in return location.coordinate});
          polyLineIC = MKPolyline(coordinates: &amp;coordinatesIC, count: locationsIC.count);
          polyLineIC.title = "ic";
          mapView.addOverlay(polyLineIC);
      }
  }
  
  func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -&gt; MKOverlayRenderer! {
      if overlay is MKPolyline
      {
          let route: MKPolyline = overlay as MKPolyline
          let routeRenderer = MKPolylineRenderer(polyline:route)
          routeRenderer.lineWidth = 3.0
          if overlay.title == "one"
          {
              routeRenderer.strokeColor = UIColor(red: 240.0/255.0, green: 68.0/255.0, blue: 0.0/255.0, alpha: 1);
          }
          else if overlay.title == "ic"
          {
              routeRenderer.strokeColor = UIColor(red: 45.0/255.0, green: 200.0/255.0, blue: 0.0/255.0, alpha: 1);
          }
          return routeRenderer
      }
  
      return nil
  }
  </code></pre>
  
  <p><strong>FINAL EDIT</strong></p>
  
  <p>Updated code:</p>
  
  <pre><code>func drawRouteOnMap()
  {
      var centerCoordinate : CLLocationCoordinate2D = icRoute[0];
      let span = MKCoordinateSpanMake(0.001, 0.001)
      var centerPosition = MKCoordinateRegionMake(centerCoordinate, span)
      mapView.setRegion(centerPosition,animated:true)
      self.mapView.mapType = MKMapType.Hybrid
  
      // first route line
      polyLine = MKPolyline(coordinates: &amp;firstRoute, count: firstRoute.count);
      polyLine.title = "one";
      mapView.addOverlay(polyLine);
  
      // IC route line
      polyLine = MKPolyline(coordinates: &amp;icRoute, count: icRoute.count);
      polyLine.title = "ic";
      mapView.addOverlay(polyLine);
  
  }
  
  func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -&gt; MKOverlayRenderer! {
      if overlay is MKPolyline
      {
          let route: MKPolyline = overlay as MKPolyline
          let routeRenderer = MKPolylineRenderer(polyline:route)
          routeRenderer.lineWidth = 3.0
          if overlay.title == "one"
          {
              routeRenderer.strokeColor = UIColor(red: 240.0/255.0, green: 68.0/255.0, blue: 0.0/255.0, alpha: 1);
          }
          else if overlay.title == "ic"
          {
              routeRenderer.strokeColor = UIColor(red: 45.0/255.0, green: 200.0/255.0, blue: 0.0/255.0, alpha: 1);
          }
          return routeRenderer
      }
  
      return nil
  }
  </code></pre>