• Das kreative Thema des Monats Oktober wird vor allem diejenigen unter Euch besonders ansprechen, denen Do-it-yourself quasi im Blut liegt. Zeigt uns Eure Improvisationskünste oder fotografiert, was andere Leute sich so im Alltag zusammengestrickt haben. --> Zum Mitmachen bitte hier klicken

Initializer for conditional binding must have Optional type, not 'CLLocation'

  • Ersteller Ersteller Thaddäus
  • Erstellt am Erstellt am

Thaddäus

Gast
Hi Leute....

Das hier ist meine Methode in Xcode 9 und Swift 4. Allerdings wirft sie mir den untenstehenden Fehler aus... Irgendjemand eine Idee wo mein Denkfehler liegt?

Code:
func showSightingsOnMap(location: CLLocation) {
        let circleQuery = geoFire!.query(at: location, withRadius: 2.5)
       
        _ = circleQuery.observe(GFEventType.keyEntered, with: { (key, location) in
           
            if let key = key, let location = location {
                let anno = PokeAnnotation(coordinate: location.coordinate, pokemonNumber: Int(key)!)
                self.mapView.addAnnotation(anno)
            }

Initializer for conditional binding must have Optional type, not 'CLLocation'
 
Die Variable ‚location‘ ist kein Optional. Deshalb ist das if let Konstrukt überflüssig.
 
  • Like
Reaktionen: Thaddäus