2016-12-28 62 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

謝謝阿南德,它真的幫助了我 –

相關問題