I am trying to write a function that will return the value from an if statement. The function looks like this:
func getJson() -> String {
if let url = URL(string: "https://api.snow.quirky.codes/cardrona") {
URLSession.shared.dataTask(with: url) { data, response, error in
if let data = data {
let jsonDecoder = JSONDecoder()
do {
let parsedJSON = try jsonDecoder.decode(Welcome.self, from: data)
for temp in parsedJSON.todaysTemp {
if let mid = temp.mid1640M {
return mid
//Causes "unexpected non-void return value in void function" error
}
}
} catch {
print(error)
}
}
}.resume()
}
}
I have tried setting a global variable and setting it to mid inside the if statement but then when I go to print it outside the function it just prints "\n".