2016-01-14 6 views
1

Итак, я настраиваю это приложение, где пользователи могут видеть свои позиции, а также иметь возможность видеть позицию других людей. Для сценария я следил за этим вопросом. how to retrive location from a PFGeopoint - (Parse.com and Swift) and show it on the map with Xcode 6.2Downcast от [PFObject] до [PFObject]

В то время как я писал код, который я получил ошибку на этой линии:

if let proximityArray = objects as? [PFObject] { 

говоря: "? [PFObject]

потупив От to '[PFObject]' только разворачивает варианты: Вы хотели использовать '!'? '

Так я пытался добавить:

for object in objects as! [PFObject]{ 

Тем не менее я получаю ту же ошибку.

Если честно, я не знаю, что такое Объекты.

Я не знаю, как это исправить, и был бы признателен за помощь в решении проблемы.

Спасибо

Для тех, кто хотел бы остальную часть кода, здесь:

func filterByProximity() { 
      PFQuery(className: "location") 
       .whereKey("where", nearGeoPoint: myGeoPoint, withinKilometers: 5000.0)  //(474) 
       .findObjectsInBackgroundWithBlock ({ 
        objects, error in 

        for object in objects as! [PFObject]{ 

        if let proximityArray = objects as? [PFObject] { 

         print("****** here the proximity matches: \(proximityArray)") 
         for near in proximityArray { 
          println("here they are \(near)") 
          if let position = near["where"] as! PFGeoPoint { 
           let theirLat = position.latituide 
           let theirLon = position.longitude 
          } 

          let theirLat = near["where"].latitude as Double 
          let theirlong = near["where"].longitude as Double 
          let location = CLLocationCoordinate2DMake(theirLat, theirlong) 
          let span = MKCoordinateSpanMake(0.05, 0.05) 
          let region = MKCoordinateRegionMake(location, span) 
          self.MapView?.setRegion(region, animated: true) 
          let theirAnotation = MKPointAnnotation() 
          theirAnotation.setCoordinate(location) 
          self.mapView.addAnnotation(anotation) 

         } 
        } 
         } 
       }) 
     } 

     filterByProximity() 

ответ

0

Пожалуйста, измените ваш код на код ниже:

func filterByProximity() { 
     PFQuery(className: "location") 
      .whereKey("where", nearGeoPoint: myGeoPoint, withinKilometers: 5000.0)  //(474) 
      .findObjectsInBackgroundWithBlock ({ 
       objects, error in 

       if let objects = objects { 
        for object in objects{ 

       let proximityArray = objects 

        print("****** here the proximity matches: \(proximityArray)") 
        for near in proximityArray { 
         println("here they are \(near)") 
         if let position = near["where"] as? PFGeoPoint { 
          let theirLat = position.latituide 
          let theirLon = position.longitude 
         } 

         let theirLat = near["where"].latitude as Double 
         let theirlong = near["where"].longitude as Double 
         let location = CLLocationCoordinate2DMake(theirLat, theirlong) 
         let span = MKCoordinateSpanMake(0.05, 0.05) 
         let region = MKCoordinateRegionMake(location, span) 
         self.MapView?.setRegion(region, animated: true) 
         let theirAnotation = MKPointAnnotation() 
         theirAnotation.setCoordinate(location) 
         self.mapView.addAnnotation(anotation) 
        } 
       } 
      }) 
    } 

    filterByProximity() 

Это должно избавиться от ошибок опций. но я думаю, что в вашем коде есть логическая ошибка, и это должно быть так:

func filterByProximity() { 
    PFQuery(className: "location") 
     .whereKey("where", nearGeoPoint: myGeoPoint, withinKilometers: 5000.0)  //(474) 
     .findObjectsInBackgroundWithBlock ({ 
      objects, error in 

      if let proximityArray = objects { 

       print("****** here the proximity matches: \(proximityArray)") 
       for near in proximityArray { 
        println("here they are \(near)") 
        if let position = near["where"] as? PFGeoPoint { 
         let theirLat = position.latituide 
         let theirLon = position.longitude 
        } 

        let theirLat = near["where"].latitude as Double 
        let theirlong = near["where"].longitude as Double 
        let location = CLLocationCoordinate2DMake(theirLat, theirlong) 
        let span = MKCoordinateSpanMake(0.05, 0.05) 
        let region = MKCoordinateRegionMake(location, span) 
        self.MapView?.setRegion(region, animated: true) 
        let theirAnotation = MKPointAnnotation() 
        theirAnotation.setCoordinate(location) 
        self.mapView.addAnnotation(anotation) 
       } 
      } 
     }) 
} 

filterByProximity() 
+0

Затем ошибка переместилась вниз. Если let proximityArray = объекты как? [PFObject] и отображая ту же самую ошибку –

+0

@TomJames, пожалуйста, см. Мой расширенный ответ. это в основном вам не нужно кастинг просто вы neet, чтобы развернуть его – Ismail

+0

Я верю, что это было. Я получил ошибку в строке «Если позиция let = рядом с ['Where'] as! PFGeopoint" say "Инициализатор для условной привязки должен иметь необязательный тип, а не PFGооо.Это может не иметь ничего общего с объектом? –

Смежные вопросы