I've been trying to access Data from a Website via Swift. To see where the problem is I put these print()'s in there. "1" is getting printed every time, but "2" isn't.
import Foundation
func getData()
{
guard let url = URL(string: "https://jsonplaceholder.typicode.com/posts") else {return}
print("1");
let session = URLSession.shared.dataTask(with: url)
{
data, response, error in
print("2");
if let error = error {
print("THere was an error: \(error.localizedDescription)")
}
else{
let jsonRes = try? JSONSerialization.jsonObject(with: data!, options: [])
print("The response: \(jsonRes)")
}
}.resume()
}
getData();