I am not able to add items to the "places" dictionary?

49 views Asked by At

Whenever I add items to "places" dictionary, it shows me an error, I basically want my app to add an annotation at the user's click on a map, and want the annotation to have the "thoroughfare" and "subThoroughfare". And then the annotation text should be updated to a table which is in another viewController.swift file. I want the dictionary to be updated with the place

it asks me to replace the semicolon with a comma.

here's the code for the global variable:

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

now I have used this variable in another viewController.swift file I have put this code under CLGeocode function, while I append the dictionary, it asks me to replace the semicolon with a comma.:

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

                let annotation = MKPointAnnotation()

                annotation.coordinate = newCoordinate

                annotation.title = title

                self.map.addAnnotation(annotation)
2

There are 2 answers

2
Sumit Oberoi On
places.append(["name":title, "lat":"\(newCoordinate.latitude)", "lon",:"\(newCoordinate.longitude)"])

Use this ^

1
Anand Nimje On

Try in your code with more safe way: -

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

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