Ios 从[PFObject]向下广播到[PFObject]

Ios 从[PFObject]向下广播到[PFObject],ios,swift,object,geolocation,Ios,Swift,Object,Geolocation,所以我正在设置这个应用程序,用户可以看到他们的位置,也可以看到其他人的位置。对于剧本,我一直在关注这个问题 在编写代码时,我在这一行遇到了一个错误: if let proximityArray = objects as? [PFObject] { 说: 从“[PFObject]”向下投射到“[PFObject]”仅展开选项: 你是想用“!”吗 因此,我试图补充: for object in objects as! [PFObject]{ 但我还是犯了同样的错误 老实说,我不知道这些东西

所以我正在设置这个应用程序,用户可以看到他们的位置,也可以看到其他人的位置。对于剧本,我一直在关注这个问题

在编写代码时,我在这一行遇到了一个错误:

  if let proximityArray = objects as? [PFObject] {
说:

从“[PFObject]”向下投射到“[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()

请将您的代码更改为以下代码:

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()

请将您的代码更改为以下代码:

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()

然后,错误向下移动到If let proximityArray=objects as?[PFObject]并显示相同的向下广播error@TomJames请看我更新的答案。基本上你不需要施法,只要你需要打开它,我相信就是这样。我在“If let position=near['Where']as!PFGeopoint”行收到一个错误,它说条件绑定的初始值设定项必须具有可选类型,而不是PFGeopoint。这可能与对象无关?Nvm,易于修复。感谢您的帮助。请查看有关上次错误的上次更新。然后,错误向下移动到If let proximityArray=objects as?[PFObject]并显示相同的向下广播error@TomJames请看我更新的答案。基本上你不需要施法,只要你需要打开它,我相信就是这样。我在“If let position=near['Where']as!PFGeopoint”行收到一个错误,它说“条件绑定的初始值设定项必须具有可选类型,而不是PFGeopoint。这可能与对象无关?Nvm,易于修复。感谢您的帮助。请查看有关上次错误的最新更新。