so I am calling a function that should just return the longitude of an inputted address. I'll append it here so you can look at it and then I will comment on it after the code:
func getLongitude(address: String) -> Double {
var longitude: Double = 0.0
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(address) {
placemarks, error in
let placemark = placemarks?.first
longitude = placemark?.location?.coordinate.longitude ?? 0.0
print("The testing longitude is \(longitude)")
}
return longitude
}
As you can see, I declared the longitude variable with a default value of 0.0. In the closure inside the function, I update longitude. The print statement confirms that the longitude was updated in that closure of the function. When longitude is accessed with the return statement outside of this closure, it returns 0.0 again (I believe the value of longitude is not mutated outside of the closure, but I don't know how to fix this). Any help would be much appreciated!