2016-12-28 64 views
0

无论何时我向“places”字典中添加项目时,它都会显示错误,我基本上希望我的应用在用户点击地图时添加注释,并希望注释具有“通道”和“subThoroughfare”。 然后注释文本应该更新为另一个viewController.swift文件中的表格。我想让字典更新的地方我无法将项目添加到“places”字典中?

它要求我用逗号替换分号。

这里是为全局变量的代码:

var places = [Dictionary<String,String>()] 

现在我已经用在我已经把下CLGeocode功能的代码另一个viewController.swift文件这个变量,而我追加的字典,它要求我用逗号:

places.append("name":title, "lat":"\(newCoordinate.latitude)", "lon",:"\(newCoordinate.longitude)") 

       let annotation = MKPointAnnotation() 

       annotation.coordinate = newCoordinate 

       annotation.title = title 

       self.map.addAnnotation(annotation) 

回答

1
places.append(["name":title, "lat":"\(newCoordinate.latitude)", "lon",:"\(newCoordinate.longitude)"]) 

使用替换分号这个^

+0

它仍然不能正常工作,它显示了这个错误: –

+0

预期分离“” –

+0

加名之前开闭架,然后最后一个字段的值 –

0

尝试在你的代码更安全的方式: -

var places = [[String: Any]]() 

places.append(["name": title ?? "", "lat": newCoordinate.latitude ?? 0.0, "lon": newCoordinate.longitude ?? 0.0]) 
+0

谢谢阿南德,它真的帮助了我 –