Hello Swift's developers:
I try to test my code that consume a Web Service in a playground. It's possible?
My code is as follows:
let endPoint = "http://host/service"
if let url = URL(string: endPoint) {
let task = URLSession.shared.dataTask(with: url) {data, response, error in
guard let httpResponse = response as? HTTPURLResponse, (200...299).contains(httpResponse.statusCode) else {
print(response)
return
}
if let mimeType = httpResponse.mimeType, mimeType == "text,html",
let data = data,
let cadena = String(data: data, encoding: .utf8) {
DispatchQueue.main.async {
}
}
}
task.resume()
}
I execute the code and playground doesn't show me error but the web service doesn't execute.
Is there an error in the code?
Best regards,
Victor.