gpt4 book ai didi

ios - 从 [PFObject] 向下转换为 [PFObject]

转载 作者:行者123 更新时间:2023-11-28 08:48:00 27 4
gpt4 key购买 nike

所以我正在设置这个应用程序,用户可以看到他们的位置,也可以看到其他人的位置。对于脚本,我正在关注这个问题。 how to retrive location from a PFGeopoint - (Parse.com and Swift) and show it on the map with Xcode 6.2

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

  if let proximityArray = objects as? [PFObject] {

说:

DownCast From '[PFObject]?' to '[PFObject]' only unwraps optionals: did you mean to use '!'?'

所以我尝试添加:

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

关于ios - 从 [PFObject] 向下转换为 [PFObject],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34793868/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com