作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如何在 Parse 上保存我创建的 MKPointAnnotation
?
@IBAction func salvaRicordo(sender: AnyObject) {
let puntoRicordo = MKPointAnnotation()
puntoRicordo.coordinate = posizioneUtente
puntoRicordo.title = nomeField.text
puntoRicordo.subtitle = descrizioneField.text
self.myMapView.addAnnotation(puntoRicordo)
print("PointAnnotation creato")
puntoRicordo.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
// The object has been saved.
} else {
// There was a problem, check error.description
}
}
最佳答案
您不能将 MKPointAnnotation
直接保存到 Parse。您可能希望保存其属性,例如 coordinate
、title
和 subtitle
。
如果你想保存坐标,你应该将它们拆分成纬度和经度。
在 Parse 中,您可以创建一个新类,将其命名为“Annotations”,添加名为“Title”、“Subtitle”、“Latitude”和“Longitude”的列,并以这种方式保存您的数据:
let myObject = PFObject(className: "Annotations")
myObject["Title"] = nomeField.text
myObject["Subtitle"] = descrizioneField.text
myObject["Latitude"] = puntoRicordo.latitude
myObject["Longitude"] = puntoRicordo.longitude
myObject.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
print("Data saved to Parse.")
} else {
print(error)
}
}
关于swift - 如何将 MKPointAnnotation 保存到 Pars?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33844398/
我是一名优秀的程序员,十分优秀!