Skip to content

Instantly share code, notes, and snippets.

@92pino
Last active October 11, 2019 10:17
Show Gist options
  • Save 92pino/790501323f8ead0de6c67b89a619d469 to your computer and use it in GitHub Desktop.
Save 92pino/790501323f8ead0de6c67b89a619d469 to your computer and use it in GitHub Desktop.
Delicious Interview
let url = URL(string: "https://httpbin.org/get")!
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
if let error = error {
print("error : "\(error.localizedDescription)")
} else {
if let response = response as? HTTPURLResponse {
print("statusCode : \(response.statusCode)")
}
if let data = data, let dataString = String(data: data, encoding: .utf8) {
print("data : \(dataString)")
}
}
}
task.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment