Swift variable declared outside closure is updated inside closure but when accessed outside closure it returns the default value?
问题 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