How do I return a double variable from a function?
class Api {
func getCoordinates(latitude: Bool) -> Double {
if (latitude) {
let url = URL(string: "https://waterservices.usgs.gov/nwis/iv/?format=json&indent=on&sites=08155200¶meterCd=00065&siteStatus=all")!
URLSession.shared.dataTask(with: url) { data, _, _ in
if let data = data {
let posts = try! JSONDecoder().decode(Post.self, from: data)
let lat = (posts.value?.timeSeries?.first?.sourceInfo?.geoLocation?.geogLocation?.latitude)
return lat
}
}
print(5)
// return 5
} else {
print(3)
return 3
}
}
}
Using this code returns:
Unexpected non-void return value in void function
I could always remove return lat
but that would kind of defeat the purpose.