For Loop Annotations not appearing

So - I use Cloud Kit query some CKRecords, which the download restaurant function returns 2, so it's not an issue of an empty array. However, as I try to take each value in the array and put it through my for loop to add an annotation to the map, nothing happens. No print statement, no annotations.

I tried putting the for loop in its own function and placing it after the download fuction but no difference. What is missing to this equation?


  let coordinate = CLLocationCoordinate2D(latitude: 42.722869, longitude: -84.488012)
        
        let region = MKCoordinateRegionMakeWithDistance(coordinate, 2000, 2000)
        
        myMap.setRegion(region, animated: true)
        
        for res in restaurantArray
        {
            
            pin = AnnotationPin(title: res.value(forKey: "Name") as! String, subtitle: "Address", theCoordinates: res.value(forKey: "Location") as! CLLocationCoordinate2D, theWeb: "https://google.com")
            
            myMap.addAnnotation(pin)
            
            self.myMap.reloadInputViews()
            
        }
            self.myMap.delegate = self

// The Cloudkit Code - all CKrecords are held in the restaurantArray - which is not empty.


 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        
        if annotation is MKUserLocation
        {
            return nil
        }
        
        let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "reuse")
        
        annotationView.image = UIImage(named: "flag-2.png")
        
        annotationView.canShowCallout = true
        
        
        let btn = UIButton(type: .detailDisclosure)
        
        annotationView.rightCalloutAccessoryView = btn
        
        return annotationView
        
    }

Replies

Is the method with the for loop being called on the main thread?

I would set the delegate *before* adding your annotations. But TheCD’s question is a very good one too.